C++ 在尝试访问json数据c++;
从HTTP POST响应中,我检索一个C++ 在尝试访问json数据c++;,c++,json,C++,Json,从HTTP POST响应中,我检索一个JSON 现在,我想获取JSON中第一个参数的值 这是一个值为1的整数 std::string postDatac = "{\"PayloadType\":1,\"TestType\":0,\"IssueDate\":\"270419\"}"; Json::Value root; Json::Reader reader; bool parsingSuccessful = reader.par
JSON
现在,我想获取JSON中第一个参数的值
这是一个值为1的整数
std::string postDatac = "{\"PayloadType\":1,\"TestType\":0,\"IssueDate\":\"270419\"}";
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse( postDatac, root );
if ( !parsingSuccessful )
{
std::cout << "Error parsing the string" ;
}
const Json::Value code = root["PayloadType"];
for ( int i = 0; i < code.size(); i++ )
{
// Print the values
std::cout << code[i] ;
}
std::string postDatac=“{\'PayloadType\'”:1、\'TestType\':0、\'IssueDate\':\'270419\}”;
Json::值根;
Json::阅读器;
bool parsingsuccesful=reader.parse(postDatac,root);
如果(!parsingSuccessful)
{
std::coutconst Json::Value code=root[“PayloadType”];
code
是一个intValue
,可以使用code.type()
找到它,它返回映射到enum ValueType::intValue
的1
code.size()
如果要从code
读取整数,只需使用
std::coutWhich JSON library you use you use with the JSON library?。我使用了这个项目中的JSON library。你在调试器中检查根对象了吗?如果操作符[]找不到具有该名称的值,它似乎会创建一个空对象。检查哪些值可用,如果有的话?你的意思是什么?bool parse(const std::string和document、Value和root、bool collectComments=true);