Changeset ee170a1 for lib


Ignore:
Timestamp:
2015-02-22T17:01:53Z (10 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Children:
56b57b1a
Parents:
989f431
Message:

Added json_object_get_tuple() which helps with implementing a JSON Object
foreach.

Location:
lib
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lib/parson.c

    r989f431 ree170a1  
    873873        return NULL;
    874874    return object->names[index];
     875}
     876
     877int json_object_get_tuple(const JSON_Object *object, size_t index,
     878                          const char **key, const JSON_Value **value) {
     879    if (index >= json_object_get_count(object))
     880        return 0;
     881    *key = object->names[index];
     882    *value = object->values[index];
     883    return 1;
    875884}
    876885
  • lib/parson.h

    r989f431 ree170a1  
    5353};
    5454typedef int JSON_Status;
    55 
     55   
    5656/* Parses first JSON value in a file, returns NULL in case of error */
    5757JSON_Value * json_parse_file(const char *filename);
     
    6060   returns NULL in case of error */
    6161JSON_Value * json_parse_file_with_comments(const char *filename);
    62 
     62   
    6363/*  Like json_parse_string, but *end is set to wherever it stopped parsing. */
    6464JSON_Value * json_parse_first(const char *string, const char **end);
    65 
     65 
    6666/*  Parses first JSON value in a string, returns NULL in case of error */
    6767JSON_Value * json_parse_string(const char *string);
     
    117117size_t        json_object_get_count(const JSON_Object *object);
    118118const char  * json_object_get_name (const JSON_Object *object, size_t index);
    119    
     119int           json_object_get_tuple(const JSON_Object *object, size_t index,
     120                                    const char **key, const JSON_Value **value); /* 0 == fail */
     121
    120122/* Creates new name-value pair or frees and replaces old value with new one. */
    121123JSON_Status json_object_set_value(JSON_Object *object, const char *name, JSON_Value *value);
Note: See TracChangeset for help on using the changeset viewer.