diff --git a/cJSON.c b/cJSON.c index da697eb..bb96f3a 100644 --- a/cJSON.c +++ b/cJSON.c @@ -660,8 +660,8 @@ static char *print_object(cJSON *item,int depth,int fmt,printbuffer *p) /* Get Array size/item / object item. */ int cJSON_GetArraySize(cJSON *array) {cJSON *c=array->child;int i=0;while(c)i++,c=c->next;return i;} -cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c=array->child; while (c && item>0) item--,c=c->next; return c;} -cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} +cJSON *cJSON_GetArrayItem(cJSON *array,int item) {cJSON *c; if (array == NULL) return NULL; c=array->child; while (c && item>0) item--,c=c->next; return c;} +cJSON *cJSON_GetObjectItem(cJSON *object,const char *string) {cJSON *c; if (object == NULL) return NULL; c=object->child; while (c && cJSON_strcasecmp(c->string,string)) c=c->next; return c;} int cJSON_HasObjectItem(cJSON *object,const char *string) { cJSON *c=object->child; while (c ) diff --git a/test.c b/test.c index 7192d68..d04c703 100644 --- a/test.c +++ b/test.c @@ -144,12 +144,30 @@ int main (int argc, const char * argv[]) { char text4[]="{\n \"Image\": {\n \"Width\": 800,\n \"Height\": 600,\n \"Title\": \"View from 15th Floor\",\n \"Thumbnail\": {\n \"Url\": \"http:/*www.example.com/image/481989943\",\n \"Height\": 125,\n \"Width\": \"100\"\n },\n \"IDs\": [116, 943, 234, 38793]\n }\n }"; char text5[]="[\n {\n \"precision\": \"zip\",\n \"Latitude\": 37.7668,\n \"Longitude\": -122.3959,\n \"Address\": \"\",\n \"City\": \"SAN FRANCISCO\",\n \"State\": \"CA\",\n \"Zip\": \"94107\",\n \"Country\": \"US\"\n },\n {\n \"precision\": \"zip\",\n \"Latitude\": 37.371991,\n \"Longitude\": -122.026020,\n \"Address\": \"\",\n \"City\": \"SUNNYVALE\",\n \"State\": \"CA\",\n \"Zip\": \"94085\",\n \"Country\": \"US\"\n }\n ]"; + char text6[] = "" + "\n" + "\n" + " \n" + " \n" + "Application Error\n" + "\n" + "\n" + " \n" + "\n" + "\n"; + /* Process each json textblock by parsing, then rebuilding: */ doit(text1); doit(text2); doit(text3); doit(text4); doit(text5); + doit(text6); /* Parse standard testfiles: */ /* dofile("../../tests/test1"); */ @@ -157,6 +175,7 @@ int main (int argc, const char * argv[]) { /* dofile("../../tests/test3"); */ /* dofile("../../tests/test4"); */ /* dofile("../../tests/test5"); */ +/* dofile("../../tests/test6"); */ /* Now some samplecode for building objects concisely: */ create_objects(); diff --git a/tests/test6 b/tests/test6 new file mode 100644 index 0000000..d5cb28f --- /dev/null +++ b/tests/test6 @@ -0,0 +1,16 @@ + + + + + + Application Error + + + + + \ No newline at end of file