Skip to content
Snippets Groups Projects
Commit 9d8f71ec authored by 13515029 - Finiko Kasula Novenda's avatar 13515029 - Finiko Kasula Novenda
Browse files

Add json parser

parent e79db571
No related merge requests found
#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));
}*/
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment