解析对象和解析数组类似, 只不过对象的一个儿子是个 key-value, key 是字符串, value 可能是任何值, key 和 value 用 ":" 分隔。
/* Build an object from the text. */
static const char *parse_object(cJSON *item,const char *value) {
cJSON *child;
if (*value!='{') {
ep=value; /* not an object! */
return 0;
}
item->type=cJSON_Object;
value=skip(value+1);
if (*value=='}') return value+1;/* empty array. */
item->child=child=cJSON_New_Item();
if (!item->child) return 0;
value=skip(parse_string(child,skip(value)));
if (!value) return 0;
child->string=child->valuestring;
child->valuestring=0;
if (*value!=':') {
ep=value; /* fail! */
return 0;
}
value=skip(parse_value(child,skip(value+1)));/* skip any spacing, get the value. */
if (!value) return 0;
while (*value==',') {
cJSON *new_item;
if (!(new_item=cJSON_New_Item()))return 0; /* memory fail */
child->next=new_item;
new_item->prev=child;
child=new_item;
value=skip(parse_string(child,skip(value+1)));
if (!value) return 0;
child->string=child->valuestring;
child->valuestring=0;
if (*value!=':') {
ep=value; /* fail! */
return 0;
}
value=skip(parse_value(child,skip(value+1)));/* skip any spacing, get the value. */
if (!value) return 0;
}
if (*value=='}') return value+1;/* end of array */
ep=value;
return 0;/* malformed. */
}
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-57098-9.html
就是将剩余的小包或者再买同批次的打开