在线时间217 小时
UID3291097
ST金币1874
蝴蝶豆0
注册时间2016-6-20
该用户从未签到
金牌会员
- 最后登录
- 2023-8-23
|
上位机发送json,{"cmd" : "device_hard","desc" : "dyaw","out":{"desc1":"V1.00","type":"string"}}STM32f1串口接收到数组里,"out":{"desc":"V1.00","type":"string"}不知道怎么解析出来,求指导。
cJSON *root;
cJSON *cmd;
cJSON *desc;
cJSON *output;
cJSON *hard;
cJSON *taskArry;
cJSON *desc1;
cJSON *type;
cJSON * temp;
int i ,icount;
root = mymalloc(SRAMIN,sizeof(cJSON));
root = cJSON_Parse((const char*)uart1Buf.Rx_Buffer);
cmd= cJSON_GetObjectItem(root,"cmd");
if(desc != NULL)
{
printf("cmd= %s\r\n",(cmd->valuestring));
}
desc= cJSON_GetObjectItem(root,"desc");
if(desc != NULL)
{
printf("desc= %s\r\n",(desc->valuestring));
}
//以下这段解析不对,不知道怎么修改了
temp=cJSON_GetObjectItem(root,"output");
if(temp != NULL)
{
icount = cJSON_GetArraySize(output);
printf( "icount=%d : \n",icount);
for(i=0; i < icount; i++)
{
output=cJSON_GetArrayItem(output, i);
if(output != NULL)
{
desc1 = cJSON_GetObjectItem(output, "desc1");
printf("desc1= %s\r\n",(desc1->valuestring));
type= cJSON_GetObjectItem(output, "type");
printf("type= %s\r\n",(type->valuestring));
}
}
}
cJSON_Delete(root);
my_free(root);
my_free(cmd);
|
|