|
发表于 2020-12-10 17:05:03
|
显示全部楼层
//cJSON解析
uint16_t i = 0, ipAddr[4] = {0};
bool json_parse_info2(const char * const context)
{
cJSON *json_context = cJSON_Parse(context);
if(json_context == NULL)
{
cJSON_Delete(json_context);
return false;
}
// 项目01
json_body = cJSON_GetObjectItemCaseSensitive(json_context, "topic");
if( !cJSON_IsString(json_body) )
{
cJSON_Delete(json_context);
return false;
}
// 项目02
json_list = cJSON_GetObjectItemCaseSensitive(json_context, "addrlist");
i = 0;
cJSON_ArrayForEach(json_body, json_list)
{
if( cJSON_IsNumber(json_body) )
{
ipAddr[i++] = json_body->valueint;
}
else
{
cJSON_Delete(json_context);
return false;
}
}
cJSON_Delete(json_context);
return true;
}
只能帮你到这里了 |
|