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:
Comments
Post a Comment