MCPcopy Index your code
hub / github.com/armink/struct2json / parse_object

Function parse_object

struct2json/src/cJSON.c:515–548  ·  view source on GitHub ↗

Build an object from the text. */

Source from the content-addressed store, hash-verified

513
514/* Build an object from the text. */
515static const char *parse_object(cJSON *item,const char *value)
516{
517 cJSON *child;
518 if (*value!='{') {ep=value;return 0;} /* not an object! */
519
520 item->type=cJSON_Object;
521 value=skip(value+1);
522 if (*value=='}') return value+1; /* empty array. */
523
524 item->child=child=cJSON_New_Item();
525 if (!item->child) return 0;
526 value=skip(parse_string(child,skip(value)));
527 if (!value) return 0;
528 child->string=child->valuestring;child->valuestring=0;
529 if (*value!=':') {ep=value;return 0;} /* fail! */
530 value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
531 if (!value) return 0;
532
533 while (*value==',')
534 {
535 cJSON *new_item;
536 if (!(new_item=cJSON_New_Item())) return 0; /* memory fail */
537 child->next=new_item;new_item->prev=child;child=new_item;
538 value=skip(parse_string(child,skip(value+1)));
539 if (!value) return 0;
540 child->string=child->valuestring;child->valuestring=0;
541 if (*value!=':') {ep=value;return 0;} /* fail! */
542 value=skip(parse_value(child,skip(value+1))); /* skip any spacing, get the value. */
543 if (!value) return 0;
544 }
545
546 if (*value=='}') return value+1; /* end of array */
547 ep=value;return 0; /* malformed. */
548}
549
550/* Render an object to text. */
551static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p)

Callers 1

parse_valueFunction · 0.85

Calls 4

skipFunction · 0.85
cJSON_New_ItemFunction · 0.85
parse_stringFunction · 0.85
parse_valueFunction · 0.85

Tested by

no test coverage detected