Jsoncpp problems

KaiserJohaan picture KaiserJohaan · Sep 26, 2011 · Viewed 8.9k times · Source

I am using Jsoncpp to parse json-formats for c++. I do not understand how it works though; there is a lack of documentation and examples to get me started, and I was wondering if anyone could give me some quick pointers. The only examples I've found deals with files...

  1. I'm using a HTTP stack to get a json-message in a buffer. For example, a buffer contains the message {"state":"Running"}. How do I use the Json::reader to parse this? Again the only example I've found deals with reading from files

  2. How do you write values to a Json-message? For example I want to write "monkey : no" and "running : yes" to a Json-message which I can then use in my GET request.

Thanks

UPDATE:

on 1), for example, how to parse a buffer containing a json-message like this:

char* buff;
uint32_t buff_size;

Answer

masoud picture masoud · Sep 26, 2011

Maybe this is good sample for first part of your question:

Json::Value values;
Json::Reader reader;
reader.parse(input, values);

Json::Value s = values.get("state","default value");