int para_get_misc_opt(char *parse_name, void *jsonIn, void **jsonOut) { lib_debug("inter"); cJSON *pJsonIn = jsonIn; int is_def=0; if(strstr(pJsonIn->string, "def")) { is_def=1; } int num = cJSON_GetArraySize(pJsonIn); if ((num == 1) && (!strncmp(cJSON_GetArrayItem(pJsonIn, 0)->valuestring, "all", strlen("all")))) { *jsonOut = cJSON_CreateObject(); Create_Json_Misc_Object(*jsonOut, is_def); return 0; } cJSON *item = NULL; cJSON * video_json=cJSON_CreateObject(); cJSON_ArrayForEach(item,pJsonIn) { int type=peek_misc_enum_type(item->valuestring); char valuestring[256]; int ret=0; if(is_def) ret=(*conf_def->get)(conf_def, item->valuestring,valuestring,sizeof(valuestring)); else ret=(*conf_cur->get)(conf_cur, item->valuestring,valuestring,sizeof(valuestring)); if(cJSON_String == type) { if(!ret) cJSON_AddStringToObject(video_json,item->valuestring,valuestring); } else if(cJSON_Number == type) { if(!ret) cJSON_AddNumberToObject(video_json,item->valuestring,atoi(valuestring)); } } *jsonOut = video_json; lib_debug("leave"); return 0; }
时间: 2023-03-28 18:02:26 浏览: 65
我可以回答这个问题。这是一个 C 语言函数,它的作用是获取一个名为 parse_name 的参数的杂项选项。它接受一个指向 jsonIn 的指针,该指针指向一个 cJSON 对象,该对象包含要解析的数据。它还接受一个指向指针的指针 jsonOut,该指针指向一个 cJSON 对象,该对象包含解析后的数据。函数中的代码检查 jsonIn 中是否包含名为 "def" 的字符串,如果包含,则将 is_def 设置为 1。然后它获取 jsonIn 中的数组大小,如果大小为 1,则...(代码未完整给出,需要补充)。
相关问题
解析代码 int para_set_misc_opt(char *parse_name, void *jsonIn) { cJSON *pJsonIn = jsonIn; cJSON *c = NULL; int need_to_notify=0; int ret=0; cJSON_ArrayForEach(c,pJsonIn) { int type=peek_misc_enum_type(c->string); if(c->type != type) { continue; } if(cJSON_IsString(c)) { ret=para_set_misc_cur_str(c->string,c->valuestring); } else { ret=para_set_misc_cur_number(c->string,c->valueint); } if(1==ret) { need_to_notify=1; } } if(need_to_notify) { lib_info("need_to_notify"); if (para_profile.misc_page_caller) para_profile.misc_page_caller(para_set_misc_opt, "all", 0); } return 0;
这段代码是一个函数,函数名为 para_set_misc_opt,接受两个参数,一个是字符串类型的 parse_name,另一个是 void 类型的 jsonIn。函数中使用了 cJSON 库来解析 jsonIn 参数,遍历其中的每一个元素,判断其类型是否符合要求,然后根据类型调用不同的函数进行处理。如果有需要通知的情况,则会调用 para_profile.misc_page_caller 函数进行通知。最后返回值为 。
解释这段代码流程和架构 int para_set_misc_opt(char *parse_name, void *jsonIn) { cJSON *pJsonIn = jsonIn; cJSON *c = NULL; int need_to_notify=0; int ret=0; cJSON_ArrayForEach(c,pJsonIn) { int type=peek_misc_enum_type(c->string); if(c->type != type) { continue; } if(cJSON_IsString(c)) { ret=para_set_misc_cur_str(c->string,c->valuestring); } else { ret=para_set_misc_cur_number(c->string,c->valueint); } if(1==ret) { need_to_notify=1; } } if(need_to_notify) { lib_info("need_to_notify"); if (para_profile.misc_page_caller) para_profile.misc_page_caller(para_set_misc_opt, "all", 0); } return 0; }
这段代码是一个函数,函数名为 para_set_misc_opt,它接受两个参数,一个是 parse_name,一个是 jsonIn。函数的作用是根据传入的 jsonIn 对象,设置一些参数的值,并在必要时通知其他模块。函数首先将 jsonIn 转换为 cJSON 对象,然后遍历这个对象的每一个元素,判断元素的类型是否符合要求。如果符合要求,就根据元素的类型设置对应参数的值,并记录下是否需要通知其他模块。最后,如果需要通知,就调用 para_profile.misc_page_caller 函数,并传入相应的参数。函数返回值为 。