C++ CJson解析json数据
cJSON
Ultralightweight JSON parser in ANSI C
项目地址:https://gitcode.com/gh_mirrors/cj/cJSON

·
字符串转成JSON(其中str为字符串)
Json::Reader Reader;
Json::Value DevJson;
Reader.parse(str,DevJson);
int dev_id = DevJson["dev_id"].asInt();
int index = DevJson["index"].asInt();
JSON转字符串(其中DevStr为字符串)
Json::Value DevJson = DevsJson[i];
std::string DevStr = DevJson.toStyledString();
printf("Msg:%s", DevStr.c_str());
JSON数组解析:
Json::Reader Reader;
Json::Value DevsJson;
Reader.parse(MsgStr, DevsJson);
int siNum = DevsJson.size();
for(int i=0; i < siNum; i++)
{
Json::Value DevJson = DevsJson[i];
std::string DevStr = DevJson.toStyledString();
printf("Msg:%s", DevStr.c_str());
}
数组添加:
Json::Value root;
Json::Value person;
person["name"] = "hello world";
person["age"] = 100;
root.append(person);




Ultralightweight JSON parser in ANSI C
最近提交(Master分支:1 个月前 )
424ce4ce
This reverts commit 5b502cdbfb21fbe5f6cf9ffbd2b96e4281a741e6.
Related to #860
10 个月前
32497300 - 11 个月前
更多推荐
所有评论(0)