Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not get multiple results #54

Open
Surapol opened this issue Jan 16, 2014 · 0 comments
Open

Could not get multiple results #54

Surapol opened this issue Jan 16, 2014 · 0 comments

Comments

@Surapol
Copy link

Surapol commented Jan 16, 2014

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 <aJSON.h>

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");

  if (results != NULL) {
    //Serial.println("Parsed successfully 3 " );
    aJsonObject* item = aJson.getObjectItem(results, "item"); 

    if (item != NULL) {
      //Serial.println("Parsed successfully 4 " );
      aJsonObject* title = aJson.getObjectItem(item, "title"); 

      if (title != NULL) {
        //Serial.println("Parsed successfully 5 " );
        //value = title->valuestring;
        Serial.println(title->valuestring);
        Serial.println("After print?");
        aJson.deleteItem(title);
      }
      aJson.deleteItem(item);
    }
    aJson.deleteItem(results);
  }
  aJson.deleteItem(query);
}
aJson.deleteItem(root);    

}
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
;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant