JsonCpp Assertion `type_ == nullValue || type_ == objectValue' 问题解决,希望能帮助到大家.转载请注明出处.
源程序
Json::Features features = Json::Features::strictMode(); Json::Reader reader(features); Json::Value value; string szbuffer(szRecvBuffer); string szName; int nAge; printf("szRecvBuffer:%s\n",szRecvBuffer); if(reader.parse(szbuffer,value)) { int nSize =value.size(); for(int i =0; i <nSize; i++) { szName =value["name"].asString(); nAge =value["age"].asInt(); cout<<szName<<endl; cout<<nAge<<endl; } }
可通过程序
Json::Features features = Json::Features::strictMode(); Json::Reader reader(features); Json::Value value; string szbuffer(szRecvBuffer); string szName; int nAge; printf("szRecvBuffer:%s\n",value)) { int nSize =value.size(); for(int i =0; i <nSize; i++) { szName =value[i]["name"].asString(); nAge =value[i]["age"].asInt(); cout<<szName<<endl; cout<<nAge<<endl; } }
无非是在value后加了区别的下标.
[{},{}] 与 {} 格式的解析要一致,否则会造成错误
此错误原因,主要是来自,所发的Json格式,和所接收的Json格式要统一.
数组格式,对数组格式. 单条记录格式,对单条记录格式.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。