在线时间302 小时
UID179403
ST金币1436
蝴蝶豆62
注册时间2015-1-9
该用户从未签到
金牌会员
- 最后登录
- 2021-12-18
|
发表于 2019-3-25 13:13:12
|
显示全部楼层
给你一个我写的demo:
// 解析JSON升级版本与url地址
static bool json_parser_object_update(char *str, int len, mico_content_t * const inContext)
{
const cJSON *json_body = NULL;
cJSON *json_context = cJSON_Parse(str);
if(json_context == NULL)
{
const char *err_ptr = cJSON_GetErrorPtr();
if(err_ptr != NULL)
{
Ql_Debug_Trace("%s", err_ptr);
}
cJSON_Delete(json_context);
return FALSE;
}
json_body = cJSON_GetObjectItem(json_context, "firm_ver");
if( !cJSON_IsString(json_body) )
{
cJSON_Delete(json_context);
return FALSE;
}
Ql_sprintf(inContext->update_ver, json_body->valuestring);
Ql_Debug_Trace("firm_ver=%s", inContext->update_ver);
json_body = cJSON_GetObjectItem(json_context, "file_url");
if( !cJSON_IsString(json_body) )
{
cJSON_Delete(json_context);
return FALSE;
}
Ql_sprintf(inContext->update_url, json_body->valuestring);
Ql_Debug_Trace("file_url=%s", inContext->update_url);
json_body = cJSON_GetObjectItem(json_context, "file_md5");
if( !cJSON_IsString(json_body) )
{
cJSON_Delete(json_context);
return FALSE;
}
Ql_sprintf(inContext->update_md5, json_body->valuestring);
Ql_Debug_Trace("file_md5=%s", inContext->update_md5);
cJSON_Delete(json_context);
return TRUE;
}
你自己参考下 |
|