Click here to Skip to main content
15,749,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

I wanna ask about Json in c++.
How can I print Json value in c++,

Let's say that I have this Json :
   "nameS" : "Jason",
   "ageS"  : "16"

How can I print "He's Jason" or "16 years old".

I already tried these :

void printmyJson(Json::Value ¶ms)
Json::Value root;
std::string name;
std::string age;
std::string mName;
for(Json::ValueIterator it = params.begin(); it!= params.end(); ++it)
 mName = it.memberName();
 name = root.get(mName,0).asString.c_str();

printf("He's %s",name\n);
printf("He is %s",mName);

But it always output this :
"He's "
"He's name"

So, the variable name is NULL instead of it's value (Jason). And variable mName is filled with Json string instead of(which I wanted)it's value (Jason).

Can someone help me on this?

many thanks
Updated 5-Sep-13 18:28pm

1 solution

I assume you are using JsonCPP

If you look at the answer to this question you will see how to iterate the json tree.[^]

This function
void CDriverConfigurator::PrintJSONValue( Json::Value &val )

prints the JSON values.

The debugger is the best way to check the values you are getting.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900