interactive-matter / aJson

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.
http://interactive-matter.org/2010/08/ajson-handle-json-with-arduino/
567 stars 136 forks source link

adding class "aJsonFileStream" inherited from aJsonStream in order to backward- compatibility with HTTPClient library #86

Open anklimov opened 8 years ago

anklimov commented 8 years ago

adding class "aJsonFileStream" inherited from aJsonStream in order to backward- compatibility with HTTPClient library Now is possible to operate directly with *FILE like streams, returned by HttpClient library and avoid intermediate buffering

Code example:


int getConfig()
{
    FILE* result;
    int returnCode ;

    HTTPClient hclient("192.168.88.2",hserver,80);
    result = hclient.getURI( FEED_URI);
    returnCode = hclient.getLastReturnCode();

    if (result!=NULL) {
      if (returnCode==200) {

          Serial.println("got Config :"); 
             aJsonFileStream as=aJsonFileStream(result);  
          root = aJson.parse(&as);

     hclient.closeStream(result);  // this is very important -- be sure to close the STREAM

        if (!root)
          {
            Serial.println("parseObject() failed");
           return -11;
            } else   

          {

            char * outstr=aJson.print(root);
            Serial.println(outstr);
             items = aJson.getObjectItem(root,"items");            
          }

            } 
    else {
      Serial.print("ERROR: Server returned ");
      Serial.println(returnCode);
      return -11;

    }

    } 
    else {
      Serial.println("failed to connect");
      Serial.println(" try again in 5 seconds");
      return -11;
                }

  return 2;
}
anklimov commented 8 years ago

That is my first attempt to contribute some changes at Github Please, let me know if something done @not a best way ))