Rapidjson需要帮助 [英] Rapidjson help needed

查看:109
本文介绍了Rapidjson需要帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我从Web服务器接收JSON数组,想知道是否有一种方法使用rapidjson按顺序访问字段值,示例代码中的字段id始终存在但是title 根据内容可能会有所不同



  for (SizeType i =  0 ; i< result_loop.Size(); i ++)
{
cout<< result_loop [i] [ id]。GetInt()<< - << result_loop [i] [ title]。GetString()<< \ n;
}





对不起泡沫



我尝试过:



for(SizeType i = 0; i< result_loop.Size(); i ++)

{

std :: cout<< result_loop [i] [id]。GetInt()<< - << result_loop [i] [title]。GetString()<< \ n;

}

解决方案

如果不确定,应该在之前检查数据是否在答案数据中任何访问以避免不必要的错误及其后果。





  for (SizeType i =  0 ; i< result_loop.Size(); i ++)
{
var id = result_loop [i] [ id];
var title = result_loop [i] [ title];
// 检查有效期
if ((id!= null)&&(title!= null)){
cout<< id.GetInt()<< - << title.GetString()<< \ n;
}
// 执行其他错误处理
}





智能错误处理是顺畅防弹软件的关键。 ; - )


Hi all I'm receiving a JSON array from a Web server and would like to know if there is a way using rapidjson to access field values by ordinal, the field "id" in the example code is always present but "title" can be different depending on the content

for (SizeType i = 0; i < result_loop.Size(); i++)
{
    cout << result_loop[i]["id"].GetInt() << " - " << result_loop[i]["title"].GetString() << "\n";
}



sorry about the fomatting

What I have tried:

for (SizeType i = 0; i < result_loop.Size(); i++)
{
std::cout << result_loop[i]["id"].GetInt() << " - " << result_loop[i]["title"].GetString() << "\n";
}

解决方案

If it is not sure, that the data is in the answer data should should check before any access to avoid unwanted errors and its consequences.


for (SizeType i = 0; i < result_loop.Size(); i++)
{
   var id =  result_loop[i]["id"];
   var title = result_loop[i]["title"];
    //check for validity
    if( (id != null) && (title !=null) ) {
       cout << id.GetInt() << " - " << title.GetString() << "\n";
    }
   // do some other error handling
}



Smart error handling is key to a smooth and bullet proof software. ;-)


这篇关于Rapidjson需要帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆