Difficulty with rapidjson .11 GetInt(), always returns 0 -
here json form:
{"simplechannels":{"item":[{"channelid":4248,"majorchannelnumber":22,"minorchannelnumber":0,"channeltype":"sll","simpleschedules":[],"channelkey":"4248_1343210400000","shortname":"kwhy","longname":"a3 los angeles 22 kwhy ind","networkaffiliation":["independent"],"logoid":0,"authcode":"fs","engchlflag":false,"hasmirror":true,"pgsource":"active","hdchlflag":true,"adultchlflag":false,"vodproviderid":0,"blackout":false,"livestreaming":"n"}]}}
here code attempts parse , extract values:
json std::string containing above:
m_guideslice.parse<0>(json.c_str()); rapidjson::value& simplechannels = m_guideslice["simplechannels"]; if (simplechannels.isobject()) { syslog_critical("simplechannels.isobject() == true\n"); rapidjson::value& channelarray= simplechannels["item"]; if (channelarray.isarray()) { syslog_critical("channelarray.isarray() == true\n"); rapidjson::value& channel = channelarray[0u]; if (channel.isobject()) { syslog_critical("channel.isobject() == true\n"); rapidjson::value& channelid = channel["channelid"]; if (channelid.isint()) { syslog_critical("channelid.isint() == true, channelid= %d\n", channelid.getint()); } else { syslog_critical("channelid.isint() == false, type= %x\n", channelid.gettype()); } rapidjson::value& majorchannelnumber = channel["majorchannelnumber"]; if (majorchannelnumber.isint()) { syslog_critical("majorchannelnumber.isint() == true, majorchannelnumber= %d\n", majorchannelnumber.getint()); } else { syslog_critical("majorchannelnumber.isint() == false, type= %x\n", majorchannelnumber.gettype()); } rapidjson::value& channeltype = channel["channeltype"]; if (channeltype.isstring()) { syslog_critical("channeltype.isstring() == true\n") syslog_critical("channeltype = %s\n", channeltype.getstring()); } else { syslog_critical("channeltype.isstring() == false, type= %x\n", channeltype.gettype()); } rapidjson::value& shortname = channel["shortname"]; if (channeltype.isstring()) { syslog_critical("shortname.isstring() == true\n") syslog_critical("shortname = %s\n", shortname.getstring()); } else { syslog_critical("shortname.isstring() == false, type= %x\n", shortname.gettype()); } } else { syslog_critical("channel.isobject() == false, type= %x\n", channel.gettype()); } } else { syslog_critical("channelarray.isarray() == false, type= %x\n", channelarray.gettype()); } } else { syslog_critical("simplechannels.isobject() == false, type= %x\n", simplechannels.gettype()); }
here extracted output syslog:
may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:78) getguide(): simplechannels.isobject() == true may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:81) getguide(): channelarray.isarray() == true may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:84) getguide(): channel.isobject() == true may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:87) getguide(): channelid.isint() == true, channelid= 0 may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:94) getguide(): majorchannelnumber.isint() == true, majorchannelnumber= 0 may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:101) getguide(): channeltype.isstring() == true may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:102) getguide(): channeltype = sll may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:109) getguide(): shortname.isstring() == true may 19 01:25:38 [bsp] [30578]: [pgws-gen log_crit tid:30744 pthr:0x7033e4f0]: (pgwsingest.cpp:110) getguide(): shortname = kwhy
the char json values extracted correctly int ones 0. i'm first time rapidjson user i'm sure there simple error making don't see right off.
thanks all,
btw, json form passes on http://www.freeformatter.com/json-validator.html think correct. machine generated anyway.
i on big endian machine , compiler must not passing appropriate flag indicate endianness.
explicitly setting flag:
define rapidjson_endian rapidjson_bigendian
in rapidsjon.h should fix this.
Comments
Post a Comment