解析此 json 的正确方法是什么?使用 ArduinoJson

What is the correct way of parsing this json? Using ArduinoJson

本文关键字:是什么 方法 使用 ArduinoJson json      更新时间:2023-10-16

>我无法使用ArduinoJson库解析此JSON的正确方法

这是我需要解析的结果 json。

{
"Error": false,
"Message": "Success",
"Sensor": [
{
"id": 10,
"mac_address": "aabbccddeeff",
"status": "ON"
}
]
}

可能要得到的目标值是"状态"的值

我试图获得一些价值并打印出来,但我什么也没得到?

到目前为止我尝试过的代码。

StaticJsonBuffer<100> jsonBuffer;
HTTPClient http;
http.begin(path);
int httpCode = http.GET();
String payload = http.getString();
JsonObject& root = jsonBuffer.parseObject(payload);
String state = root["Sensor"];
Serial.println(payload);
Serial.println(state);    //Print request response payload

搜索时,我发现作者创建了一个助手来转换您定义的 json 字符串。 你可以在这里找到它 https://bblanchon.github.io/ArduinoJson/assistant/index.html

Sensor是一个列表,其中包含具有所需属性status的单个对象。

String state = root["Sensor"][0]["status"];