Closed GoogleCodeExporter closed 9 years ago
Please refer to the new file attached
Original comment by vijayson...@gmail.com
on 12 Aug 2013 at 7:14
Attachments:
Your attached code should assert in debug mode, as objJson does not contain a
key called "name".
Original comment by milo...@gmail.com
on 12 Aug 2013 at 8:47
[deleted comment]
Hi
could you please give hint how to traverse through this json string
"[ \
{ \
\"ResponseName\":\"Table\", \
\"ListData\": \
[ \
{\"Param\":\"Power\"}, \
{\"Param\":\"Def\"}, \
{\"Param\":\"Opt\"}, \
] \
} \
]";
As this is an array , but I not able to get its member.
Please help
Original comment by vijayson...@gmail.com
on 14 Aug 2013 at 10:23
Please check "Querying Array" in
https://code.google.com/p/rapidjson/wiki/UserGuide#3._Value
Original comment by milo...@gmail.com
on 14 Aug 2013 at 1:23
Hi,
Sorry to trouble you again and again. But using the same I am getting strange reponse that's why I have posted my query here.
Code is :
#include "stdafx.h"
#include "URI.h"
#include <iostream>
#include <cstdio>
#include "rapidjson\document.h" // rapidjson's DOM-style API
#include "rapidjson\prettywriter.h" // for stringify JSON
#include "rapidjson\filestream.h" // wrapper of C stream for prettywriter as
output
#include "rapidjson\stringbuffer.h"
#include <cstdio>
using namespace std;
using namespace openutils;
using namespace rapidjson;
rapidjson::Document objJson; // Default template parameter uses UTF8 and
MemoryPoolAllocator.
rapidjson::StringBuffer strBuff(0, 1024);
rapidjson::Document::AllocatorType& allocator = objJson.GetAllocator();
rapidjson::Value objVal(rapidjson::kObjectType);
int main(int argc, char *argv[])
{
static const char* kTypeNames[] = { "Null", "False", "True", "Object", "Array",
"String", "Number" };
const char json[] = "[ \
{ \
\"ResponseName\":\"Table\", \
\"ListData\": \
[ \ {\"Param\":\"Power\"}, \ {\"Param\":\"Def\"}, \
{\"Param\":\"Opt\"} \
] \
} \
]";
if(objJson.Parse<0>(json).HasParseError())
{
printf("Error parsing ");
}
const Value& a = objJson; // Using a reference for consecutive
assert(a.IsArray());
for (SizeType i = 0; i < a.Size(); i++) // rapidjson uses SizeType instead of
size_t.
printf("a[%d] = %d /n", i, a[i].GetInt());
printf("%s /n", a[SizeType(0)].GetString());
if(objJson.IsArray())
{
for (Value::ConstValueIterator itr = a.Begin(); itr != a.End(); ++itr)
printf("%d \n", itr->GetInt());
for (Value::ConstMemberIterator itr = objJson.MemberBegin(); itr !=
objJson.MemberEnd(); ++itr)
printf("Type of member %s is %s\n", itr->name.GetString(),
kTypeNames[itr->value.GetType()]);
}
}
catch(...)
{
printf("Error unknown");
}
getchar();
return 0;
}
==> The response which I get is different everytime. such as (check the
attachment)
Original comment by vijayson...@gmail.com
on 16 Aug 2013 at 6:37
Attachments:
Would you think that you should use 0L instead ? to remove all chances this is
ambiguous?
Original comment by thege...@gmail.com
on 18 Jun 2014 at 10:36
Original comment by milo...@gmail.com
on 30 Jun 2014 at 1:57
Original issue reported on code.google.com by
vijayson...@gmail.com
on 12 Aug 2013 at 7:09Attachments: