I need a simple working code to parse a json file in the local memory.

Jul 9, 2014 at 3:56 AM
Dear Guys,
 Could you please kindly post a working simple code in c++ to parse a json file with c++ rest sdk?
This will be a great help,

Thanks in advance...
Jul 9, 2014 at 3:59 AM
Hi Wilsoftson,

Basically just call ::web::json::value::parse(...) with a string or a stringstream. Take a look at the documentation for examples.

Jul 9, 2014 at 4:43 AM
Thank you stevegates,

by the way, I am a newbie, so I need some detailed answer to help me.

As for my case, I have a file named "data.json". I would like to know how to make a call to this json file and parse it and use the value to my local c++ application.

Kindly looking forward to your reply with some full sample code.

Thank you in advance.....
Jul 11, 2014 at 3:14 AM
Hi Wilsoftson,

There are many different ways you can do this. Like I mentioned all you need to do is get the json data into string or a stream. Here is one such example using a std::istream:
    std::ifstream inputStream("json.data", std::ifstream::in);
    ::web::json::value v = ::web::json::value::parse(inputStream);