Local copy
Dependencies: C12832_lcd ConfigFile EthernetInterface LM75B MMA7660 MQTTPacket mbed-rtos mbed
Fork of IBMIoTClientExampleForLPC1768 by
src/cJSON.h@13:65e87bd958bd, 2014-07-02 (annotated)
- Committer:
- rajathishere
- Date:
- Wed Jul 02 15:07:40 2014 +0000
- Revision:
- 13:65e87bd958bd
- Parent:
- 11:0fa63599f5a0
Rename QuickstartClient to ExampleClient
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rajathishere | 11:0fa63599f5a0 | 1 | /* |
rajathishere | 11:0fa63599f5a0 | 2 | Copyright (c) 2009 Dave Gamble |
rajathishere | 11:0fa63599f5a0 | 3 | |
rajathishere | 11:0fa63599f5a0 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
rajathishere | 11:0fa63599f5a0 | 5 | of this software and associated documentation files (the "Software"), to deal |
rajathishere | 11:0fa63599f5a0 | 6 | in the Software without restriction, including without limitation the rights |
rajathishere | 11:0fa63599f5a0 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
rajathishere | 11:0fa63599f5a0 | 8 | copies of the Software, and to permit persons to whom the Software is |
rajathishere | 11:0fa63599f5a0 | 9 | furnished to do so, subject to the following conditions: |
rajathishere | 11:0fa63599f5a0 | 10 | |
rajathishere | 11:0fa63599f5a0 | 11 | The above copyright notice and this permission notice shall be included in |
rajathishere | 11:0fa63599f5a0 | 12 | all copies or substantial portions of the Software. |
rajathishere | 11:0fa63599f5a0 | 13 | |
rajathishere | 11:0fa63599f5a0 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
rajathishere | 11:0fa63599f5a0 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
rajathishere | 11:0fa63599f5a0 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
rajathishere | 11:0fa63599f5a0 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
rajathishere | 11:0fa63599f5a0 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
rajathishere | 11:0fa63599f5a0 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
rajathishere | 11:0fa63599f5a0 | 20 | THE SOFTWARE. |
rajathishere | 11:0fa63599f5a0 | 21 | */ |
rajathishere | 11:0fa63599f5a0 | 22 | |
rajathishere | 11:0fa63599f5a0 | 23 | #ifndef cJSON__h |
rajathishere | 11:0fa63599f5a0 | 24 | #define cJSON__h |
rajathishere | 11:0fa63599f5a0 | 25 | |
rajathishere | 11:0fa63599f5a0 | 26 | #ifdef __cplusplus |
rajathishere | 11:0fa63599f5a0 | 27 | extern "C" |
rajathishere | 11:0fa63599f5a0 | 28 | { |
rajathishere | 11:0fa63599f5a0 | 29 | #endif |
rajathishere | 11:0fa63599f5a0 | 30 | |
rajathishere | 11:0fa63599f5a0 | 31 | /* cJSON Types: */ |
rajathishere | 11:0fa63599f5a0 | 32 | #define cJSON_False 0 |
rajathishere | 11:0fa63599f5a0 | 33 | #define cJSON_True 1 |
rajathishere | 11:0fa63599f5a0 | 34 | #define cJSON_NULL 2 |
rajathishere | 11:0fa63599f5a0 | 35 | #define cJSON_Number 3 |
rajathishere | 11:0fa63599f5a0 | 36 | #define cJSON_String 4 |
rajathishere | 11:0fa63599f5a0 | 37 | #define cJSON_Array 5 |
rajathishere | 11:0fa63599f5a0 | 38 | #define cJSON_Object 6 |
rajathishere | 11:0fa63599f5a0 | 39 | |
rajathishere | 11:0fa63599f5a0 | 40 | #define cJSON_IsReference 256 |
rajathishere | 11:0fa63599f5a0 | 41 | |
rajathishere | 11:0fa63599f5a0 | 42 | /* The cJSON structure: */ |
rajathishere | 11:0fa63599f5a0 | 43 | typedef struct cJSON { |
rajathishere | 11:0fa63599f5a0 | 44 | struct cJSON *next,*prev; /* next/prev allow you to walk array/object chains. Alternatively, use GetArraySize/GetArrayItem/GetObjectItem */ |
rajathishere | 11:0fa63599f5a0 | 45 | struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */ |
rajathishere | 11:0fa63599f5a0 | 46 | |
rajathishere | 11:0fa63599f5a0 | 47 | int type; /* The type of the item, as above. */ |
rajathishere | 11:0fa63599f5a0 | 48 | |
rajathishere | 11:0fa63599f5a0 | 49 | char *valuestring; /* The item's string, if type==cJSON_String */ |
rajathishere | 11:0fa63599f5a0 | 50 | int valueint; /* The item's number, if type==cJSON_Number */ |
rajathishere | 11:0fa63599f5a0 | 51 | double valuedouble; /* The item's number, if type==cJSON_Number */ |
rajathishere | 11:0fa63599f5a0 | 52 | |
rajathishere | 11:0fa63599f5a0 | 53 | char *string; /* The item's name string, if this item is the child of, or is in the list of subitems of an object. */ |
rajathishere | 11:0fa63599f5a0 | 54 | } cJSON; |
rajathishere | 11:0fa63599f5a0 | 55 | |
rajathishere | 11:0fa63599f5a0 | 56 | typedef struct cJSON_Hooks { |
rajathishere | 11:0fa63599f5a0 | 57 | void *(*malloc_fn)(size_t sz); |
rajathishere | 11:0fa63599f5a0 | 58 | void (*free_fn)(void *ptr); |
rajathishere | 11:0fa63599f5a0 | 59 | } cJSON_Hooks; |
rajathishere | 11:0fa63599f5a0 | 60 | |
rajathishere | 11:0fa63599f5a0 | 61 | /* Supply malloc, realloc and free functions to cJSON */ |
rajathishere | 11:0fa63599f5a0 | 62 | extern void cJSON_InitHooks(cJSON_Hooks* hooks); |
rajathishere | 11:0fa63599f5a0 | 63 | |
rajathishere | 11:0fa63599f5a0 | 64 | |
rajathishere | 11:0fa63599f5a0 | 65 | /* Supply a block of JSON, and this returns a cJSON object you can interrogate. Call cJSON_Delete when finished. */ |
rajathishere | 11:0fa63599f5a0 | 66 | extern cJSON *cJSON_Parse(const char *value); |
rajathishere | 11:0fa63599f5a0 | 67 | /* Render a cJSON entity to text for transfer/storage. Free the char* when finished. */ |
rajathishere | 11:0fa63599f5a0 | 68 | extern char *cJSON_Print(cJSON *item); |
rajathishere | 11:0fa63599f5a0 | 69 | /* Render a cJSON entity to text for transfer/storage without any formatting. Free the char* when finished. */ |
rajathishere | 11:0fa63599f5a0 | 70 | extern char *cJSON_PrintUnformatted(cJSON *item); |
rajathishere | 11:0fa63599f5a0 | 71 | /* Delete a cJSON entity and all subentities. */ |
rajathishere | 11:0fa63599f5a0 | 72 | extern void cJSON_Delete(cJSON *c); |
rajathishere | 11:0fa63599f5a0 | 73 | |
rajathishere | 11:0fa63599f5a0 | 74 | /* Returns the number of items in an array (or object). */ |
rajathishere | 11:0fa63599f5a0 | 75 | extern int cJSON_GetArraySize(cJSON *array); |
rajathishere | 11:0fa63599f5a0 | 76 | /* Retrieve item number "item" from array "array". Returns NULL if unsuccessful. */ |
rajathishere | 11:0fa63599f5a0 | 77 | extern cJSON *cJSON_GetArrayItem(cJSON *array,int item); |
rajathishere | 11:0fa63599f5a0 | 78 | /* Get item "string" from object. Case insensitive. */ |
rajathishere | 11:0fa63599f5a0 | 79 | extern cJSON *cJSON_GetObjectItem(cJSON *object,const char *string); |
rajathishere | 11:0fa63599f5a0 | 80 | |
rajathishere | 11:0fa63599f5a0 | 81 | /* For analysing failed parses. This returns a pointer to the parse error. You'll probably need to look a few chars back to make sense of it. Defined when cJSON_Parse() returns 0. 0 when cJSON_Parse() succeeds. */ |
rajathishere | 11:0fa63599f5a0 | 82 | extern const char *cJSON_GetErrorPtr(void); |
rajathishere | 11:0fa63599f5a0 | 83 | |
rajathishere | 11:0fa63599f5a0 | 84 | /* These calls create a cJSON item of the appropriate type. */ |
rajathishere | 11:0fa63599f5a0 | 85 | extern cJSON *cJSON_CreateNull(void); |
rajathishere | 11:0fa63599f5a0 | 86 | extern cJSON *cJSON_CreateTrue(void); |
rajathishere | 11:0fa63599f5a0 | 87 | extern cJSON *cJSON_CreateFalse(void); |
rajathishere | 11:0fa63599f5a0 | 88 | extern cJSON *cJSON_CreateBool(int b); |
rajathishere | 11:0fa63599f5a0 | 89 | extern cJSON *cJSON_CreateNumber(double num); |
rajathishere | 11:0fa63599f5a0 | 90 | extern cJSON *cJSON_CreateString(const char *string); |
rajathishere | 11:0fa63599f5a0 | 91 | extern cJSON *cJSON_CreateArray(void); |
rajathishere | 11:0fa63599f5a0 | 92 | extern cJSON *cJSON_CreateObject(void); |
rajathishere | 11:0fa63599f5a0 | 93 | |
rajathishere | 11:0fa63599f5a0 | 94 | /* These utilities create an Array of count items. */ |
rajathishere | 11:0fa63599f5a0 | 95 | extern cJSON *cJSON_CreateIntArray(const int *numbers,int count); |
rajathishere | 11:0fa63599f5a0 | 96 | extern cJSON *cJSON_CreateFloatArray(const float *numbers,int count); |
rajathishere | 11:0fa63599f5a0 | 97 | extern cJSON *cJSON_CreateDoubleArray(const double *numbers,int count); |
rajathishere | 11:0fa63599f5a0 | 98 | extern cJSON *cJSON_CreateStringArray(const char **strings,int count); |
rajathishere | 11:0fa63599f5a0 | 99 | |
rajathishere | 11:0fa63599f5a0 | 100 | /* Append item to the specified array/object. */ |
rajathishere | 11:0fa63599f5a0 | 101 | extern void cJSON_AddItemToArray(cJSON *array, cJSON *item); |
rajathishere | 11:0fa63599f5a0 | 102 | extern void cJSON_AddItemToObject(cJSON *object,const char *string,cJSON *item); |
rajathishere | 11:0fa63599f5a0 | 103 | /* Append reference to item to the specified array/object. Use this when you want to add an existing cJSON to a new cJSON, but don't want to corrupt your existing cJSON. */ |
rajathishere | 11:0fa63599f5a0 | 104 | extern void cJSON_AddItemReferenceToArray(cJSON *array, cJSON *item); |
rajathishere | 11:0fa63599f5a0 | 105 | extern void cJSON_AddItemReferenceToObject(cJSON *object,const char *string,cJSON *item); |
rajathishere | 11:0fa63599f5a0 | 106 | |
rajathishere | 11:0fa63599f5a0 | 107 | /* Remove/Detatch items from Arrays/Objects. */ |
rajathishere | 11:0fa63599f5a0 | 108 | extern cJSON *cJSON_DetachItemFromArray(cJSON *array,int which); |
rajathishere | 11:0fa63599f5a0 | 109 | extern void cJSON_DeleteItemFromArray(cJSON *array,int which); |
rajathishere | 11:0fa63599f5a0 | 110 | extern cJSON *cJSON_DetachItemFromObject(cJSON *object,const char *string); |
rajathishere | 11:0fa63599f5a0 | 111 | extern void cJSON_DeleteItemFromObject(cJSON *object,const char *string); |
rajathishere | 11:0fa63599f5a0 | 112 | |
rajathishere | 11:0fa63599f5a0 | 113 | /* Update array items. */ |
rajathishere | 11:0fa63599f5a0 | 114 | extern void cJSON_ReplaceItemInArray(cJSON *array,int which,cJSON *newitem); |
rajathishere | 11:0fa63599f5a0 | 115 | extern void cJSON_ReplaceItemInObject(cJSON *object,const char *string,cJSON *newitem); |
rajathishere | 11:0fa63599f5a0 | 116 | |
rajathishere | 11:0fa63599f5a0 | 117 | /* Duplicate a cJSON item */ |
rajathishere | 11:0fa63599f5a0 | 118 | extern cJSON *cJSON_Duplicate(cJSON *item,int recurse); |
rajathishere | 11:0fa63599f5a0 | 119 | /* Duplicate will create a new, identical cJSON item to the one you pass, in new memory that will |
rajathishere | 11:0fa63599f5a0 | 120 | need to be released. With recurse!=0, it will duplicate any children connected to the item. |
rajathishere | 11:0fa63599f5a0 | 121 | The item->next and ->prev pointers are always zero on return from Duplicate. */ |
rajathishere | 11:0fa63599f5a0 | 122 | |
rajathishere | 11:0fa63599f5a0 | 123 | /* ParseWithOpts allows you to require (and check) that the JSON is null terminated, and to retrieve the pointer to the final byte parsed. */ |
rajathishere | 11:0fa63599f5a0 | 124 | extern cJSON *cJSON_ParseWithOpts(const char *value,const char **return_parse_end,int require_null_terminated); |
rajathishere | 11:0fa63599f5a0 | 125 | |
rajathishere | 11:0fa63599f5a0 | 126 | extern void cJSON_Minify(char *json); |
rajathishere | 11:0fa63599f5a0 | 127 | |
rajathishere | 11:0fa63599f5a0 | 128 | /* Macros for creating things quickly. */ |
rajathishere | 11:0fa63599f5a0 | 129 | #define cJSON_AddNullToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateNull()) |
rajathishere | 11:0fa63599f5a0 | 130 | #define cJSON_AddTrueToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateTrue()) |
rajathishere | 11:0fa63599f5a0 | 131 | #define cJSON_AddFalseToObject(object,name) cJSON_AddItemToObject(object, name, cJSON_CreateFalse()) |
rajathishere | 11:0fa63599f5a0 | 132 | #define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b)) |
rajathishere | 11:0fa63599f5a0 | 133 | #define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n)) |
rajathishere | 11:0fa63599f5a0 | 134 | #define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s)) |
rajathishere | 11:0fa63599f5a0 | 135 | |
rajathishere | 11:0fa63599f5a0 | 136 | /* When assigning an integer value, it needs to be propagated to valuedouble too. */ |
rajathishere | 11:0fa63599f5a0 | 137 | #define cJSON_SetIntValue(object,val) ((object)?(object)->valueint=(object)->valuedouble=(val):(val)) |
rajathishere | 11:0fa63599f5a0 | 138 | |
rajathishere | 11:0fa63599f5a0 | 139 | #ifdef __cplusplus |
rajathishere | 11:0fa63599f5a0 | 140 | } |
rajathishere | 11:0fa63599f5a0 | 141 | #endif |
rajathishere | 11:0fa63599f5a0 | 142 | |
rajathishere | 11:0fa63599f5a0 | 143 | #endif |