使用ArduinoJson库生成百度天工物接入JSON数据

#include <ArduinoJson.h>
int sensorA0=51;
float Temperature=28;
StaticJsonDocument<200> doc;

// Inside the brackets, 200 is the RAM allocated to this document.
// Don’t forget to change this value to match your requirement.
// Use arduinojson.org/v6/assistant to compute the capacity.

void JSON(){

JsonObject desired = doc.createNestedObject(“desired”);
JsonObject reported = doc.createNestedObject(“reported”);
reported[“D1_Temperature”] = Temperature;
reported[“D1_Humidity”] = sensorA0;

}

void setup() {
// Initialize Serial port
Serial.begin(9600);
while (!Serial) continue;
JSON();
String data = doc.as();
const char* data_t = data.c_str();

serializeJsonPretty(doc, Serial);
// The above line prints:
/*
{
“desired”: {},
“reported”: {
“D1_Temperature”: 28,
“D1_Humidity”: 51
}
*/
}
// Start a new line
Serial.println();
Serial.println(data_t);
// The above line prints:
//{“desired”:{},“reported”:{“D1_Temperature”:23,“D1_Humidity”:455}}
void loop() {
// not used in this example
}

百度天工JSON数据格式

使用ArduinoJson库生成百度天工物接入JSON数据

串口显示效果

使用ArduinoJson库生成百度天工物接入JSON数据使用ArduinoJson库的串口打印,前面为啥会有一段乱码???不知道,但是并不影响数据上传,管他呢 ^ _ ^。有知道的大神麻烦解释一下,谢谢,看着挺别扭的,我这里开发板使用的是小黑板esp8266。

补充

上面有一句代码显示不完整,截个图
使用ArduinoJson库生成百度天工物接入JSON数据