From 9d8f71ece0053e0653d4c84a8d785c1a404f6f75 Mon Sep 17 00:00:00 2001
From: finikokasulanovenda <13515029@std.stei.itb.ac.id>
Date: Sun, 8 Apr 2018 16:15:43 +0700
Subject: [PATCH] Add json parser

---
 src/json_parser.cpp/json_parser.cpp.ino | 55 +++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
 create mode 100644 src/json_parser.cpp/json_parser.cpp.ino

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 0000000..5140484
--- /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));
+}*/
+
+
-- 
GitLab