今天师傅让给做json数据的转换,网上随便找了个实验了下,打印怎么不行
const char* str="{\"uploadid\": \"UP000000\",\"code\": 1000,\"msg\": \"\",\"files\": \"\"}";
Json::Reader reader;
Json::Value root;
if(reader.parse(str,root))
{
cout<<root["code"].asInt()<<endl;
Json::Value value;
value["hello"]=1000;
root["code"]=value;
cout<<str<<endl;
return 1;
}
经过实验,原来jsoncpp库并不会改变str的内存,相反它会改变root的结构,加入这一行代码
std::string out=root.toStyledString();
cout<<out<<endl;