I tried an Example Code that uses the JSON library but I get the following error:
invalid digit "9" in octal constant.
But the Variable for the String exaple in this Code is defined as a const char.
Whith the my example String it desent't work.
if I remove the time part of the String I get the following error:
missing terminating " character
/*
JSON Object
This sketch demonstrates how to use various features
of the Official Arduino JSON library, in particular for JSON objects.
This example code is in the public domain.
*/
#include <Arduino_JSON.h>
//const char input[] = "{"result":true,"count":42,"foo":"bar"}";
const char input[] = "{"time":"2019-09-11 14:11:28","model":"inFactory sensor","id":80,""temperature_C":17.33333,"humidit y":66}";
void setup() {
Serial.begin(9600);
while (!Serial);
demoParse();
demoCreation();
}
void loop() {
}
void demoParse() {
Serial.println("parse");
Serial.println("=====");
JSONVar myObject = JSON.parse(input);
// JSON.typeof(jsonVar) can be used to get the type of the var
if (JSON.typeof(myObject) == "undefined") {
Serial.println("Parsing input failed!");
return;
}
Serial.print("JSON.typeof(myObject) = ");
Serial.println(JSON.typeof(myObject)); // prints: object
// myObject.hasOwnProperty(key) checks if the object contains an entry for key
if (myObject.hasOwnProperty("result")) {
Serial.print("myObject["result"] = ");
Serial.println((bool) myObject["result"]);
}
if (myObject.hasOwnProperty("count")) {
Serial.print("myObject["count"] = ");
Serial.println((int) myObject["count"]);
}
if (myObject.hasOwnProperty("count")) {
Serial.print("myObject["count"] = ");
Serial.println((double) myObject["count"]);
}
if (myObject.hasOwnProperty("foo")) {
Serial.print("myObject["foo"] = ");
Serial.println((const char*) myObject["foo"]);
}
// JSON vars can be printed using print or println
Serial.print("myObject = ");
Serial.println(myObject);
Serial.println();
}
void demoCreation() {
Serial.println("creation");
Serial.println("========");
JSONVar myObject;
myObject["hello"] = "world";
myObject["true"] = true;
myObject["x"] = 42;
Serial.print("myObject.keys() = ");
Serial.println(myObject.keys());
// JSON.stringify(myVar) can be used to convert the json var to a String
String jsonString = JSON.stringify(myObject);
Serial.print("JSON.stringify(myObject) = ");
Serial.println(jsonString);
Serial.println();
// myObject.keys() can be used to get an array of all the keys in the object
JSONVar keys = myObject.keys();
for (int i = 0; i < keys.length(); i++) {
JSONVar value = myObject[keys*];*
- Serial.print("JSON.typeof(myObject[");*
_ Serial.print(keys*);_
_ Serial.print("]) = ");_
_ Serial.println(JSON.typeof(value));_
_ Serial.print("myObject[");_
_ Serial.print(keys);
Serial.print("] = ");
Serial.println(value);
Serial.println();
}
Serial.println();
// setting a value to undefined can remove it from the object*
* myObject["x"] = undefined;
// you can also change a value*
* myObject["hello"] = "there!";
Serial.print("myObject = ");
Serial.println(myObject);
}*_