diff --git a/src/json_parser.cpp/json_parser.cpp.ino b/src/json_parser.cpp/json_parser.cpp.ino new file mode 100644 index 0000000000000000000000000000000000000000..514048435cb5589ace0783be2a24253b42b85081 --- /dev/null +++ b/src/json_parser.cpp/json_parser.cpp.ino @@ -0,0 +1,55 @@ +#include <ArduinoJson.h> + +bool isSuccess; +int year; +int humidity; +int light; + +char json[] = "{\"success\":true,\"year\":3,\"humidity\":5,\"light\":10}"; + +void ReadJson(); +//char[] GenerateString(); + +void setup() { + // put your setup code here, to run once: + +} + +void loop() { +// put your main code here, to run repeatedly: + +} + +void ReadJson() { + Serial.begin(9600); + while (!Serial) continue; + + StaticJsonBuffer<200> jsonBuffer; + + JsonObject& jsonReader = jsonBuffer.parseObject(json); + + if (!jsonReader.success()) { + Serial.println("parseObject() failed"); + return; + } + + isSuccess = jsonReader["success"]; + year = jsonReader["year"]; + humidity = jsonReader["humidity"]; + light = jsonReader["light"]; + + //char[] jsonString = GenerateString(); + + //Serial.println(jsonString); + Serial.println(isSuccess); + Serial.println(year); + Serial.println(humidity); + Serial.println(light); +} + +/*char[] GenerateString() { + char[] string; + return ("age : " + itoa(year,string,10) + " humidity : " + itoa(humidity,string,10) + " light : " + itoa(light,string,10)); +}*/ + +