c++ - How to parse the JSON result for module values and take the action? -


how parse url outputs (json packets) below:

{"result":"ok","db":[{"id":"2","createdate":"0000-00-00 00:00:00","modifydate":"0000-00-00 00:00:00","module":null,"serial":null,"company":"1","firstname":"an ","lastname":"","email1":"","email2":"","email3":"","phone":null,"mobile":null,"pincode":null,"username":null,"email4":""},{"id":"3","createdate":"0000-00-00 00:00:00","modifydate":"0000-00-00 00:00:00","module":"red","serial":null,"company":"2","firstname":"an ","lastname":"","email1":"","email2":"","email3":"","phone":null,"mobile":null,"pincode":null,"username":null,"email4":""},{"id":"4","createdate":"0000-00-00 00:00:00","modifydate":"0000-00-00 00:00:00","module":"red","serial":null,"company":"3","firstname":"an ","lastname":"","email1":"","email2":"","email3":"","phone":null,"mobile":null,"pincode":null,"username":null,"email4":""} 

from url results read id , module values only

module:null , id:2  module:red , id:3   module:red , id:4 

if value "red" execute digitalwrite(id_number, high); (in case 2 execution should happen pin 3 , pin 4)

arduino yun code:

#include <bridge.h> #include <httpclient.h>  void setup() {   pinmode(13, output);   bridge.begin(); }  void loop() {         httpclient client;   /* returns json result */   client.get("http://example.com/ajax/pinoutput");   string result;    while (client.available()) {     char c = client.read();     result = result + c;   }    /* check value red json result , read id insert in digitalwrite(here); */   if(result.indexof("red") < 0) {     digitalwrite(13, high);     delay(1000);   } else {     digitalwrite(13, low);         delay(1000);   }    /* delay crawl interval */   delay(2000); } 

you need parser. simple library job following:

http://sourceforge.net/projects/cjson/


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -