JsonCpp Assertion `type_ == nullValue || type_ == objectValue'

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格式要统一.


数组格式,对数组格式. 单条记录格式,对单条记录格式.

相关文章

AJAX是一种基于JavaScript和XML的技术,能够使网页实现异步交...
在网页开发中,我们常常需要通过Ajax从后端获取数据并在页面...
在前端开发中,经常需要循环JSON对象数组进行数据操作。使用...
AJAX(Asynchronous JavaScript and XML)是一种用于创建 We...
AJAX技术被广泛应用于现代Web开发,它可以在无需重新加载页面...
Ajax是一种通过JavaScript和HTTP请求交互的技术,可以实现无...