C++ cJSON

您所在的位置:网站首页 cjson_replaceiteminobject C++ cJSON

C++ cJSON

#C++ cJSON| 来源: 网络整理| 查看: 265

本文整理汇总了C++中cJSON_strdup函数的典型用法代码示例。如果您正苦于以下问题:C++ cJSON_strdup函数的具体用法?C++ cJSON_strdup怎么用?C++ cJSON_strdup使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了cJSON_strdup函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: cJSON_AddItemToObject void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item) {if (!item) return; if (item->string) cJSON_free(item->string);item->string=cJSON_strdup(string);cJSON_AddItemToArray(object,item);}开发者ID:josevh,项目名称:zbx-module-neustar-wpm,代码行数:1,代码来源:cJSON.c 示例2: cJSON_ReplaceItemInObject void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=object->child;while(c && cJSON_strcasecmp(c->string,string))i++,c=c->next;if(c){newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}开发者ID:josevh,项目名称:zbx-module-neustar-wpm,代码行数:1,代码来源:cJSON.c 示例3: SWITCH_DECLARE SWITCH_DECLARE(cJSON *)cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);}return item;}开发者ID:alleywind,项目名称:FreeSWITCH,代码行数:1,代码来源:switch_json.c 示例4: switch /* Render a value to text. */ static char *print_value(cJSON *item,int depth,int fmt,printbuffer *p) { char *out=0; if (!item) { return 0; } if (p) { switch ((item->type)&255) { case cJSON_NULL: { out=ensure(p,5); if (out) { strcpy(out,"null"); } break; } case cJSON_False: { out=ensure(p,6); if (out) { strcpy(out,"false"); } break; } case cJSON_True: { out=ensure(p,5); if (out) { strcpy(out,"true"); } break; } case cJSON_Number: out=print_number(item,p); break; case cJSON_String: out=print_string(item,p); break; case cJSON_Array: out=print_array(item,depth,fmt,p); break; case cJSON_Object: out=print_object(item,depth,fmt,p); break; } } else { switch ((item->type)&255) { case cJSON_NULL: out=cJSON_strdup("null"); break; case cJSON_False: out=cJSON_strdup("false"); break; case cJSON_True: out=cJSON_strdup("true"); break; case cJSON_Number: out=print_number(item,0); break; case cJSON_String: out=print_string(item,0); break; case cJSON_Array: out=print_array(item,depth,fmt,0); break; case cJSON_Object: out=print_object(item,depth,fmt,0); break; } } return out; }开发者ID:JasonYSU,项目名称:VETH3000Switch,代码行数:69,代码来源:cJSON.c 示例5: cJSON *cJSON_CreateString(mp_pool_t *p,const char *string) {cJSON *item=cJSON_New_Item(p);if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(p,string);}return item;}开发者ID:zonquan,项目名称:dumphttp,代码行数:1,代码来源:cJSON.c 示例6: if /* Render the cstring provided to an escaped version that can be printed. */ static char *print_string_ptr(const char *str) { const char *ptr; char *ptr2,*out; int len=0; unsigned char token; if (!str) return cJSON_strdup(""); ptr=str; while ((token=*ptr) && ++len) { if (strchr("\"\\\b\f\n\r\t",token)) len++; else if (token31 && *ptr!='\"' && *ptr!='\\') *ptr2++=*ptr++; else { *ptr2++='\\'; switch (token=*ptr++) { case '\\': *ptr2++='\\'; break; case '\"': *ptr2++='\"'; break; case '\b': *ptr2++='b'; break; case '\f': *ptr2++='f'; break; case '\n': *ptr2++='n'; break; case '\r': *ptr2++='r'; break; case '\t': *ptr2++='t'; break; default: sprintf(ptr2,"u%04x",token); ptr2+=5; break; /* escape and print */ } } } *ptr2++='\"'; *ptr2++=0; return out; }开发者ID:S-V,项目名称:Lollipop,代码行数:62,代码来源:cJSON.cpp 示例7: cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string);if(!item->valuestring){cJSON_Delete(item);return 0;}}return item;}开发者ID:MikauSchekzen,项目名称:kb-profiler-driver,代码行数:1,代码来源:cJSON.c 示例8: cJSON *cJSON_CreateString(const char *string) {cJSON *item=cJSON_New_Item();item->type=cJSON_String;item->valuestring=cJSON_strdup(string);return item;}开发者ID:AChurikov,项目名称:Movid,代码行数:1,代码来源:cJSON.c 示例9: cJSON_New_Item /* Duplication */ cJSON *cJSON_Duplicate(const cJSON *item, cjbool recurse) { cJSON *newitem = NULL; cJSON *cptr = NULL; cJSON *nptr = NULL; cJSON *newchild = NULL; /* Bail on bad ptr */ if (!item) { return NULL; } /* Create new item */ newitem = cJSON_New_Item(); if (!newitem) { return NULL; } /* Copy over all vars */ newitem->type = item->type & (~cJSON_IsReference); newitem->valueint = item->valueint; newitem->valuedouble = item->valuedouble; if (item->valuestring) { newitem->valuestring = cJSON_strdup(item->valuestring); if (!newitem->valuestring) { cJSON_Delete(newitem); return NULL; } } if (item->string) { newitem->string = (item->type&cJSON_StringIsConst) ? item->string : cJSON_strdup(item->string); if (!newitem->string) { cJSON_Delete(newitem); return NULL; } } /* If non-recursive, then we're done! */ if (!recurse) { return newitem; } /* Walk the ->next chain for the child. */ cptr = item->child; while (cptr) { newchild = cJSON_Duplicate(cptr, 1); /* Duplicate (with recurse) each item in the ->next chain */ if (!newchild) { cJSON_Delete(newitem); return NULL; } if (nptr) { /* If newitem->child already set, then crosswire ->prev and ->next and move on */ nptr->next = newchild; newchild->prev = nptr; nptr = newchild; } else { /* Set newitem->child and move to it */ newitem->child = newchild; nptr = newchild; } cptr = cptr->next; } return newitem; }开发者ID:FSMaxB,项目名称:cJSON,代码行数:73,代码来源:cJSON.c 示例10: gw_lc_bind_device //.........这里部分代码省略......... op_ret = OPRT_CJSON_GET_ERR; goto ERR_EXIT; }else if(NULL == child && (i == CNTSOF(str)-1)) { prop->prop_value.scale = 0; }else { switch(i) { case 0: prop->prop_value.max = child->valueint; break; case 1: prop->prop_value.min = child->valueint; break; //case 2: prop->prop_value.step = child->valueint; break; case 2: prop->prop_value.scale = child->valueint; break; } } } }else if(!strcmp(child->valuestring,"string")) { dp_desc->prop_tp = PROP_STR; child = cJSON_GetObjectItem(next,"maxlen"); if(NULL == child) { PR_ERR("get maxlen null"); op_ret = OPRT_CJSON_GET_ERR; goto ERR_EXIT; } prop->prop_str.max_len = child->valueint; prop->prop_str.value = Malloc(prop->prop_str.max_len+1); if(NULL == prop->prop_str.value) { PR_ERR("malloc error"); op_ret = OPRT_MALLOC_FAILED; goto ERR_EXIT; } }else { dp_desc->prop_tp = PROP_ENUM; child = cJSON_GetObjectItem(next,"range"); if(NULL == child) { PR_ERR("get range null"); op_ret = OPRT_CJSON_GET_ERR; goto ERR_EXIT; } INT i,num; num = cJSON_GetArraySize(child); if(num == 0) { PR_ERR("get array size error"); op_ret = OPRT_CJSON_GET_ERR; goto ERR_EXIT; } prop->prop_enum.pp_enum = Malloc(num*sizeof(CHAR *)); if(NULL == prop->prop_enum.pp_enum) { PR_ERR("malloc error"); op_ret = OPRT_MALLOC_FAILED; goto ERR_EXIT; } prop->prop_enum.cnt = num; for(i = 0;i < num;i++) { cJSON *c_child = cJSON_GetArrayItem(child,i); if(NULL == c_child) { PR_ERR("get array null"); op_ret = OPRT_CJSON_GET_ERR; goto ERR_EXIT; } prop->prop_enum.pp_enum[i] = cJSON_strdup(c_child->valuestring); if(NULL == prop->prop_enum.pp_enum[i]) { PR_ERR("malloc error"); op_ret = OPRT_MALLOC_FAILED; goto ERR_EXIT; } } } } os_mutex_get(&gw_mutex, OS_WAIT_FOREVER); if(NULL == gw_cntl.dev) { gw_cntl.dev = dev_cntl; }else { DEV_CNTL_N_S *tmp_dev_cntl = gw_cntl.dev; while(tmp_dev_cntl->next) { tmp_dev_cntl = tmp_dev_cntl->next; } tmp_dev_cntl->next = dev_cntl; } gw_cntl.dev_num++; os_mutex_put(&gw_mutex); if(root) { cJSON_Delete(root); } return OPRT_OK; ERR_EXIT: if(dev_cntl) { Free(dev_cntl); } if(root) { cJSON_Delete(root); } return op_ret; }开发者ID:tomsparrow25,项目名称:wifisdk_for_wm,代码行数:101,代码来源:sysdata_adapter.c 示例11: cJSON *cJSON_CreateString(const char *string, ngx_pool_t *pool) {cJSON *item=cJSON_New_Item(pool);if(item){item->type=cJSON_String;item->valuestring=cJSON_strdup(string, pool);}return item;}开发者ID:1nfused,项目名称:RedPitaya,代码行数:1,代码来源:cJSON.c 示例12: cJSON_Duplicate /* Duplication */ cJSON *ICACHE_FLASH_ATTR cJSON_Duplicate(cJSON *item, int recurse) { cJSON *newitem, *cptr, *nptr = 0, *newchild; /* Bail on bad ptr */ if (!item) { return 0; } /* Create new item */ newitem = cJSON_New_Item(); if (!newitem) { return 0; } /* Copy over all vars */ newitem->type = item->type & (~cJSON_IsReference), newitem->valueint = item->valueint, newitem->valuedouble = item->valuedouble; if (item->valuestring) { newitem->valuestring = cJSON_strdup(item->valuestring); if (!newitem->valuestring) { cJSON_Delete(newitem); return 0; } } if (item->string) { newitem->string = cJSON_strdup(item->string); if (!newitem->string) { cJSON_Delete(newitem); return 0; } } /* If non-recursive, then we're done! */ if (!recurse) { return newitem; } /* Walk the ->next chain for the child. */ cptr = item->child; while (cptr) { newchild = cJSON_Duplicate(cptr, 1); /* Duplicate (with recurse) each item in the ->next chain */ if (!newchild) { cJSON_Delete(newitem); return 0; } if (nptr) { nptr->next = newchild, newchild->prev = nptr; /* If newitem->child already set, then crosswire ->prev and ->next and move on */ nptr = newchild; } else { newitem->child = newchild; /* Set newitem->child and move to it */ nptr = newchild; } cptr = cptr->next; } return newitem; }开发者ID:hxy513696765,项目名称:ESP8266JSON-WEATHER,代码行数:68,代码来源:cJSON.c 示例13: cJSON_ReplaceItemInObject void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem){int i=0;cJSON *c=cJSON_GetObjectItemV2(object,string,&i);if(c){if(newitem->string) cJSON_free(newitem->string);newitem->string=cJSON_strdup(string);cJSON_ReplaceItemInArray(object,i,newitem);}}开发者ID:shengang1006,项目名称:libjson,代码行数:1,代码来源:cJSON.c

注:本文中的cJSON_strdup函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3