C++: program returns different JSON result than if url is accessed manually -
C++: program returns different JSON result than if url is accessed manually -
i'm working on project manipulating roomba. roowifi microcontroller i'm using writes sensor info json file every often, , i'm trying fetch json, parse it, , base of operations actions off of output.
i'm having issue grabbing info json @ url. file @ address,
http://10.0.0.1/roomba.json
and can manually come in address chrome , see data. however, when grab json file programmatically, info values zero.
the format of json, , how see in chrome, is:
{ "response": { "r13": { "name": "angle", "value": "0" }, "r14": { "name": "charging state", "value": "4" }, "r18": { "name": "charge", "value": "863" }, "r19": { "name": "capacity", "value": "1618" } } }
what returned programmatically is:
{ "response": { "r13": { "name": "angle", "value": "0" }, "r14": { "name": "charging state", "value": "0" }, "r18": { "name": "charge", "value": "0" }, "r19": { "name": "capacity", "value": "0" } } }
i'm using qt creator , c++. i'm not proficient @ c++ , have never used qt (the library functions packaged this), thought first effort using qt json parser , url requests implemented incorrectly. copied code evgeny @ http://stackoverflow.com/a/13096222/2415349. code retrieves json file, of 'values' zero.
i've tried putting fetch/parse functions in loop, each time same thing returned.
what odd can json file populated values in python using json , urllib2 libraries.
can shed lite why occurring? i've ever parsed files on machine. request getting default json, when roomba turned off? computer or browser need set way (im using mac osx 10.9.4).
edit: the code i've used evgeny's reply (get_http() used)
string get_http(const string &server,const string &path); using namespace boost::property_tree; stringstream temp; temp << get_http("10.0.0.1","/roomba.json"); cout << "original json:" << endl; cout << temp.str(); cout << string(256,'*') << endl; ptree root; read_json(temp,root); cout << "printed xml:" << endl; write_xml(cout,root);
i'm seeing output mentioned above when temp.str() , root printed cout.
edit 2:
i've realized request returning same json. original set run application, , watch output programme returning. stop application, , go 10.0.0.1/roomba.json manually.
does have thought why when application running json file set zeros, when not (but connected device) json file outputs data?
c++ json getjson
Comments
Post a Comment