下载cJSON
https://quantum6.blog.csdn.net/article/details/118605802
范例文本
{ "command": "function", "name": "openDocument", "params": { "count": 2, "param0": "taishan.docx", "param1": false } }
解析取值
cJSON* root = cJSON_Parse(pData); cJSON *item = cJSON_GetObjectItem(root, "name"); char* name = cJSON_GetStringValue(item); item = cJSON_GetObjectItem(root, "params"); cJSON* pItem = cJSON_GetObjectItem(pJson, "count"); printf("%d, %s, %f", pItem->valueint, pItem->valuestring, pItem->valuedouble); printf("%s, %f", cJSON_GetNumberValue(pItem), cJSON_GetStringValue(pItem), ); //cJSON_IsInvalid, cJSON_IsFalse, cJSON_IsTrue, cJSON_IsBool,cJSON_IsNull, //cJSON_IsNumber, cJSON_IsString, cJSON_IsArray, cJSON_IsObject, cJSON_IsRaw