aJson is an Arduino library to enable JSON processing with Arduino. It easily enables you to decode, create, manipulate and encode JSON directly from and to data structures.
With the code below, I could not get next result. Only first query result show up then halt right after the first success function "parseJson" .It does not print the "Circle" after the function.
With the code below, I could not get next result. Only first query result show up then halt right after the first success function "parseJson" .It does not print the "Circle" after the function.
include
char jsonString[256];
void setup() { String js=""; Serial.begin(115200); Serial.println(jsonString); Serial.println("Starting to parse"); js+="{"; js+= "\"query\":{\"count\":1,\"created\":\"2012-08-04T14:46:03Z\",\"lang\":\"en-US\",\"results\":{\"item\":{\"title\":\"Handling FTP usernames with @ in them\"}}},"; js+= "\"circle0\":{\"x\":5,\"y\":10,\"r\":15},"; js+= "\"string0\":{\"x\":20,\"y\":25}"; js+="}"; js.toCharArray(jsonString,sizeof(jsonString)); //Serial.println("Circle"); //parseCircle(jsonString); //Serial.println("String"); //parseString(jsonString); parseJson(jsonString); Serial.println("Circle"); } boolean parseJson(char jsonString){ aJsonObject *root=aJson.parse(jsonString); if(root!=NULL){ aJsonObject query = aJson.getObjectItem(root, "query"); if (query != NULL) { //Serial.println("Parsed successfully 2 " ); aJsonObject* results = aJson.getObjectItem(query, "results");
} Serial.println("Out"); return true; } boolean parseCircle(char jsonString) { aJsonObject root = aJson.parse(jsonString); if (root != NULL) {
aJsonObject _circle=aJson.getObjectItem(root,"circle0"); if(circle!=NULL){ aJsonObject x=aJson.getObjectItem(circle,"x"); if(x!=NULL){ if(x->type==aJson_Int){ Serial.print("Circle x:"); Serial.println(x->valueint); } aJson.deleteItem(x); } else{ Serial.print("Circle x null"); } aJson.deleteItem(circle); } else{ Serial.println("Circle Null"); } //aJson.deleteItem(root); } else{ Serial.println("Circle root null"); } } boolean parseString(char jsonString) { aJsonObject_ root = aJson.parse(jsonString); if (root != NULL) {
aJsonObject string=aJson.getObjectItem(root,"string0"); if(string!=NULL){ aJsonObject x=aJson.getObjectItem(string,"x"); if(x!=NULL){ if(x->type==aJson_Int){ Serial.print("string0 x:"); Serial.println(x->valueint); } aJson.deleteItem(x); } else{ Serial.print("String x null"); } aJson.deleteItem(string); } else{ Serial.println("String Null"); } //aJson.deleteItem(root); } else{ Serial.println("String root null"); } }
void loop() { // Nothing to do ; }