下载的cJSON代码里面,发现main和test里面都没有对json数据进行提取的实例,所以手工测试了一下,仅供参考
void testJson()
{
char *out;cJSON *json,*jsonTemp;
json=cJSON_Parse((char *)USART1_RX_BUF);
if (!json) {printf("Error before: [%s]\n",cJSON_GetErrorPtr());}
else
{
out=cJSON_Print(json);
printf("%s:%x:%x\n",out,json,out);
jsonTemp=cJSON_GetObjectItem(json,"name");
printf("name:%s\n",jsonTemp->valuestring);
jsonTemp=cJSON_GetArrayItem(json,1);
printf("phone:%d\n",jsonTemp->valueint);
jsonTemp=cJSON_GetArrayItem(json,2);
jsonTemp=cJSON_GetArrayItem(jsonTemp,0);
printf("params-area:%s\n",jsonTemp->valuestring);
cJSON_Delete(json);
myfree(SRAMEX,out);
}
}
串口助手输入输出如下: