我正在努力解决这段代码而我无法理解它。 所以我设法从JSON中的api返回。我在String Client中收到回复。但我无法从这个字符串中获取任何数据。我已经检查了我的代码几个小时但没有接近。这里出了什么问题?
我的JSON代码是:
{
"devices": {
"thermostats": {
"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU": {
"humidity": 40,
"locale": "nl-NL",
"temperature_scale": "C",
"is_using_emergency_heat": false,
"has_fan": false,
"software_version": "5.6.6-4",
"has_leaf": false,
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA",
"device_id": "e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU",
"name": "Downstairs",
"can_heat": true,
"can_cool": false,
"target_temperature_c": 23.5,
"target_temperature_f": 75,
"target_temperature_high_c": 24,
"target_temperature_high_f": 75,
"target_temperature_low_c": 20,
"target_temperature_low_f": 68,
"ambient_temperature_c": 15,
"ambient_temperature_f": 60,
"away_temperature_high_c": 24,
"away_temperature_high_f": 76,
"away_temperature_low_c": 8.5,
"away_temperature_low_f": 48,
"eco_temperature_high_c": 24,
"eco_temperature_high_f": 76,
"eco_temperature_low_c": 8.5,
"eco_temperature_low_f": 48,
"is_locked": false,
"locked_temp_min_c": 20,
"locked_temp_min_f": 68,
"locked_temp_max_c": 22,
"locked_temp_max_f": 72,
"sunlight_correction_active": false,
"sunlight_correction_enabled": true,
"structure_id": "vEJb634MNif-xVxcn3hIdIAAdT2p5L7beo2amUiTuBVoEPy3C0PAFw",
"fan_timer_active": false,
"fan_timer_timeout": "1970-01-01T00:00:00.000Z",
"fan_timer_duration": 15,
"previous_hvac_mode": "",
"hvac_mode": "heat",
"time_to_target": "~0",
"time_to_target_training": "ready",
"where_name": "Downstairs",
"label": "",
"name_long": "Downstairs Thermostat",
"is_online": true,
"last_connection": "2018-02-17T08:56:41.512Z",
"hvac_state": "heating"
}
}
},
"structures": {
"NzsPBklZNQBC4FVqmRUaVLqMhPVJII3IzQ0QfhReeGv_UCagNdtMhg": {
"name": "Structure 1",
"country_code": "US",
"time_zone": "America/Los_Angeles",
"away": "home",
"structure_id": "NzsPBklZNQBC4FVqmRUaVLqMhPVJII3IzQ0QfhReeGv_UCagNdtMhg",
"wheres": {
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6FUQ2RVTLC5w": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6FUQ2RVTLC5w",
"name": "Backyard"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4POqHyZw5GHQ": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4POqHyZw5GHQ",
"name": "Basement"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5QjU1FA_slkA": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5QjU1FA_slkA",
"name": "Bedroom"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5kuu8P9K1TFQ": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5kuu8P9K1TFQ",
"name": "Den"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4ncylMQyZn-g": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4ncylMQyZn-g",
"name": "Dining Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA",
"name": "Downstairs"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5rtDphaQytaQ": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5rtDphaQytaQ",
"name": "Driveway"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5Z5XxmZr9Aeg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5Z5XxmZr9Aeg",
"name": "Entryway"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7r62EA7u7DWw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7r62EA7u7DWw",
"name": "Family Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6o_Kr6tv-CSA": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6o_Kr6tv-CSA",
"name": "Front Yard"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5OO0kfgPRADw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5OO0kfgPRADw",
"name": "Guest House"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5AMihmAgobTw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5AMihmAgobTw",
"name": "Guest Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6MLDlLEu4-2A": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6MLDlLEu4-2A",
"name": "Hallway"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5t08bO8j0Mzg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5t08bO8j0Mzg",
"name": "Kids Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7p1ASlDNUnHg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7p1ASlDNUnHg",
"name": "Kitchen"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7uLdRQIIIvww": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7uLdRQIIIvww",
"name": "Living Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5W7d3KtKxzfg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5W7d3KtKxzfg",
"name": "Master Bedroom"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6arlkBKu_K8Q": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6arlkBKu_K8Q",
"name": "Office"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7gc73riRgkvw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7gc73riRgkvw",
"name": "Outside"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6c07Ca7PZt2A": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6c07Ca7PZt2A",
"name": "Upstairs"
}
}
},
"vEJb634MNif-xVxcn3hIdIAAdT2p5L7beo2amUiTuBVoEPy3C0PAFw": {
"name": "CNT/FAI",
"country_code": "BE",
"time_zone": "Europe/Brussels",
"away": "home",
"thermostats": [
"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU"
],
"structure_id": "vEJb634MNif-xVxcn3hIdIAAdT2p5L7beo2amUiTuBVoEPy3C0PAFw",
"wheres": {
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6FUQ2RVTLC5w": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6FUQ2RVTLC5w",
"name": "Backyard"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4POqHyZw5GHQ": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4POqHyZw5GHQ",
"name": "Basement"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5QjU1FA_slkA": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5QjU1FA_slkA",
"name": "Bedroom"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5kuu8P9K1TFQ": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5kuu8P9K1TFQ",
"name": "Den"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4ncylMQyZn-g": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG4ncylMQyZn-g",
"name": "Dining Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA",
"name": "Downstairs"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5rtDphaQytaQ": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5rtDphaQytaQ",
"name": "Driveway"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5Z5XxmZr9Aeg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5Z5XxmZr9Aeg",
"name": "Entryway"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7r62EA7u7DWw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7r62EA7u7DWw",
"name": "Family Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6o_Kr6tv-CSA": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6o_Kr6tv-CSA",
"name": "Front Yard"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5OO0kfgPRADw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5OO0kfgPRADw",
"name": "Guest House"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5AMihmAgobTw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5AMihmAgobTw",
"name": "Guest Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6MLDlLEu4-2A": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6MLDlLEu4-2A",
"name": "Hallway"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5t08bO8j0Mzg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5t08bO8j0Mzg",
"name": "Kids Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7p1ASlDNUnHg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7p1ASlDNUnHg",
"name": "Kitchen"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7uLdRQIIIvww": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7uLdRQIIIvww",
"name": "Living Room"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5W7d3KtKxzfg": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG5W7d3KtKxzfg",
"name": "Master Bedroom"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6arlkBKu_K8Q": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6arlkBKu_K8Q",
"name": "Office"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7gc73riRgkvw": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7gc73riRgkvw",
"name": "Outside"
},
"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6c07Ca7PZt2A": {
"where_id": "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG6c07Ca7PZt2A",
"name": "Upstairs"
}
}
}
},
"metadata": {
"access_token": "SECURITY",
"client_version": 2,
"user_id": "SECURITY"
}
}
我的ESP8266代码是:
String json = "";
while (client.available()) {
String line = client.readStringUntil('\r');
Serial.println("reply was:");
Serial.println("==========");
Serial.println(line);
Serial.println("==========");
Serial.println("closing connection");
digitalWrite(gpio13Led, LOW);
json = json + line;
Serial.print("json");
Serial.println(json);
}
// Reading JSON
DynamicJsonBuffer jsonBuffer(10833);
JsonObject& root = jsonBuffer.parseObject(json);
Serial.print("JsonObject: ");
JsonObject& thermoStat = root["devices"]["thermostats"]["e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU"];
const char* hvacState = thermoStat["hvac_state"]; // "heating"
Serial.println("hvac");
Serial.print(hvacState);
//compare hvacState
if (hvacState == "off") {
Serial.print("Off");
}
if (hvacState == "heating"){
Serial.print("On");
}
}
我的串口输出是:
reply was:
==========
{"devices":{"thermostats":{"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU":{"humidity...
==========
closing connection
json
JsonObject: hvac
类似的代码mentioned here 确实有效。但是我在使用const char *,而现在我从字符串中得到了api的响应。我不知道如何以不同的方式做到这一点。
在答案中提出一些建议之后,我尝试使用以下代码来获取相同的JSON代码:
#include <ArduinoJson.h>
void setup() {
Serial.begin(115200);
Serial.println("TEST START");
//Serial.println("Buffer" + bufferSize);
const char* json = "{\blanked oUT}}";
Serial.println(json);
DynamicJsonBuffer jsonBuffer(10833);
JsonObject& root = jsonBuffer.parseObject(json);
//Serial.print("JsonObject: ");
//Serial.println((int)root["devices"]["thermostats"]["e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU"]);
JsonObject& thermostat = root["devices"]["thermostats"]["e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU"];
const char* hvacState = thermostat["hvac_state"]; // "heating"
Serial.println("hvac:");
Serial.println(hvacState);
if (hvacState == "off") {
Serial.print("Uit");
}
if (hvacState == "heating"){
Serial.print("Aan");
}
}
void loop() {
// put your main code here, to run repeatedly:
}
然后是:
TEST START
{"devices":{all blanked out}}
hvac:
off
正如您所看到的,除了IF()
之外,其他一切都有效。但是,如果我将const char*
更改为String
代码无法正常工作。不幸的是我需要解析一个字符串才能让我的完整代码工作。
答案 0 :(得分:0)
可能值得使用您传递给JSON对象的硬编码JSON字符串进行单独测试,以确保解析按预期工作。
ArduinoJSON Assistant应该有助于存根JSON解析。
根据您的评论和JSON content on your other question,您可能会感到不完整或混乱。
这是JSON响应的手动格式化版本。请记住,最后一部分只是确保使用有效的JSON对象:
{
"devices":
{
"thermostats":
{
"exxx":
{
"humidity":40,
"locale":"nl-NL",
"temperature_scale":"C",
"is_using_emergency_heat":false,
"has_fan":false,
"software_version":"5.6.6-4",
"has_leaf":true,
"where_id":"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA",
"device_id":"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU",
"name":"Downstairs",
"can_heat":true,
"can_cool":false,
"target_temperature_c":15.0,
"target_temperature_f":59,
"target_temperature_high_c":24.0,
"target_temperature_high_f":75,
"target_temperature_low_c":20.0,
"target_temperature_low_f":68,
"ambient_temperature_c":15.5,
"ambient_temperature_f":61,
"away_temperature_high_c":24.0,
"away_temperature_high_f":76,
"away_temperature_low_c":8.5,
"away_temperature_low_f":48,
"eco_temperature_high_c":24.0,
"eco_temperature_high_f":76,
"eco_temperature_low_c":8.5,
"eco_temperature_low_f":48,
"is_locked":false,
"locked_temp_min_c":20.0,
"locked_temp_min_f":68,
"locked_temp_max_c":22.0,
"locked_temp_max_f":72,
"sunlight_correction_active":false,
"sunlight_correction_enabled":true,
"structure_id":"vEJb634MNif-xxx",
"something_else_?":
{
"access_token":"xxxx",
"client_version":2,
"user_id":"xxxx"
}
}
}
}
}
有了这个,ArduinoJson助手可以生成解析代码:
const size_t bufferSize = 3*JSON_OBJECT_SIZE(1) + JSON_OBJECT_SIZE(3) + JSON_OBJECT_SIZE(37) + 1100;
DynamicJsonBuffer jsonBuffer(bufferSize);
const char* json = "{\"devices\":{\"thermostats\":{\"exxx\":{\"humidity\":40,\"locale\":\"nl-NL\",\"temperature_scale\":\"C\",\"is_using_emergency_heat\":false,\"has_fan\":false,\"software_version\":\"5.6.6-4\",\"has_leaf\":true,\"where_id\":\"YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA\",\"device_id\":\"e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU\",\"name\":\"Downstairs\",\"can_heat\":true,\"can_cool\":false,\"target_temperature_c\":15,\"target_temperature_f\":59,\"target_temperature_high_c\":24,\"target_temperature_high_f\":75,\"target_temperature_low_c\":20,\"target_temperature_low_f\":68,\"ambient_temperature_c\":15.5,\"ambient_temperature_f\":61,\"away_temperature_high_c\":24,\"away_temperature_high_f\":76,\"away_temperature_low_c\":8.5,\"away_temperature_low_f\":48,\"eco_temperature_high_c\":24,\"eco_temperature_high_f\":76,\"eco_temperature_low_c\":8.5,\"eco_temperature_low_f\":48,\"is_locked\":false,\"locked_temp_min_c\":20,\"locked_temp_min_f\":68,\"locked_temp_max_c\":22,\"locked_temp_max_f\":72,\"sunlight_correction_active\":false,\"sunlight_correction_enabled\":true,\"structure_id\":\"vEJb634MNif-xxx\",\"something_else_?\":{\"access_token\":\"xxxx\",\"client_version\":2,\"user_id\":\"xxxx\"}}}}}";
JsonObject& root = jsonBuffer.parseObject(json);
JsonObject& devices_thermostats_exxx = root["devices"]["thermostats"]["exxx"];
int devices_thermostats_exxx_humidity = devices_thermostats_exxx["humidity"]; // 40
const char* devices_thermostats_exxx_locale = devices_thermostats_exxx["locale"]; // "nl-NL"
const char* devices_thermostats_exxx_temperature_scale = devices_thermostats_exxx["temperature_scale"]; // "C"
bool devices_thermostats_exxx_is_using_emergency_heat = devices_thermostats_exxx["is_using_emergency_heat"]; // false
bool devices_thermostats_exxx_has_fan = devices_thermostats_exxx["has_fan"]; // false
const char* devices_thermostats_exxx_software_version = devices_thermostats_exxx["software_version"]; // "5.6.6-4"
bool devices_thermostats_exxx_has_leaf = devices_thermostats_exxx["has_leaf"]; // true
const char* devices_thermostats_exxx_where_id = devices_thermostats_exxx["where_id"]; // "YygkopgUUc_cIFnCNG7GRDIIQnENO0ScVx9Pa78qfG7XyH-9WDdVgA"
const char* devices_thermostats_exxx_device_id = devices_thermostats_exxx["device_id"]; // "e97ayjdpIOkPa4vZFxHggZMXiHKfhsyU"
const char* devices_thermostats_exxx_name = devices_thermostats_exxx["name"]; // "Downstairs"
bool devices_thermostats_exxx_can_heat = devices_thermostats_exxx["can_heat"]; // true
bool devices_thermostats_exxx_can_cool = devices_thermostats_exxx["can_cool"]; // false
int devices_thermostats_exxx_target_temperature_c = devices_thermostats_exxx["target_temperature_c"]; // 15
int devices_thermostats_exxx_target_temperature_f = devices_thermostats_exxx["target_temperature_f"]; // 59
int devices_thermostats_exxx_target_temperature_high_c = devices_thermostats_exxx["target_temperature_high_c"]; // 24
int devices_thermostats_exxx_target_temperature_high_f = devices_thermostats_exxx["target_temperature_high_f"]; // 75
int devices_thermostats_exxx_target_temperature_low_c = devices_thermostats_exxx["target_temperature_low_c"]; // 20
int devices_thermostats_exxx_target_temperature_low_f = devices_thermostats_exxx["target_temperature_low_f"]; // 68
float devices_thermostats_exxx_ambient_temperature_c = devices_thermostats_exxx["ambient_temperature_c"]; // 15.5
int devices_thermostats_exxx_ambient_temperature_f = devices_thermostats_exxx["ambient_temperature_f"]; // 61
int devices_thermostats_exxx_away_temperature_high_c = devices_thermostats_exxx["away_temperature_high_c"]; // 24
int devices_thermostats_exxx_away_temperature_high_f = devices_thermostats_exxx["away_temperature_high_f"]; // 76
float devices_thermostats_exxx_away_temperature_low_c = devices_thermostats_exxx["away_temperature_low_c"]; // 8.5
int devices_thermostats_exxx_away_temperature_low_f = devices_thermostats_exxx["away_temperature_low_f"]; // 48
int devices_thermostats_exxx_eco_temperature_high_c = devices_thermostats_exxx["eco_temperature_high_c"]; // 24
int devices_thermostats_exxx_eco_temperature_high_f = devices_thermostats_exxx["eco_temperature_high_f"]; // 76
float devices_thermostats_exxx_eco_temperature_low_c = devices_thermostats_exxx["eco_temperature_low_c"]; // 8.5
int devices_thermostats_exxx_eco_temperature_low_f = devices_thermostats_exxx["eco_temperature_low_f"]; // 48
bool devices_thermostats_exxx_is_locked = devices_thermostats_exxx["is_locked"]; // false
int devices_thermostats_exxx_locked_temp_min_c = devices_thermostats_exxx["locked_temp_min_c"]; // 20
int devices_thermostats_exxx_locked_temp_min_f = devices_thermostats_exxx["locked_temp_min_f"]; // 68
int devices_thermostats_exxx_locked_temp_max_c = devices_thermostats_exxx["locked_temp_max_c"]; // 22
int devices_thermostats_exxx_locked_temp_max_f = devices_thermostats_exxx["locked_temp_max_f"]; // 72
bool devices_thermostats_exxx_sunlight_correction_active = devices_thermostats_exxx["sunlight_correction_active"]; // false
bool devices_thermostats_exxx_sunlight_correction_enabled = devices_thermostats_exxx["sunlight_correction_enabled"]; // true
const char* devices_thermostats_exxx_structure_id = devices_thermostats_exxx["structure_id"]; // "vEJb634MNif-xxx"
JsonObject& devices_thermostats_exxx_something_else_ = devices_thermostats_exxx["something_else_?"];
const char* devices_thermostats_exxx_something_else__access_token = devices_thermostats_exxx_something_else_["access_token"]; // "xxxx"
int devices_thermostats_exxx_something_else__client_version = devices_thermostats_exxx_something_else_["client_version"]; // 2
const char* devices_thermostats_exxx_something_else__user_id = devices_thermostats_exxx_something_else_["user_id"]; // "xxxx"
回到你的问题:&#34; hvac_state&#34;此数据中不存在,因此这可能是您尝试无效的原因之一。
此外,如评论中所述,测试ESP外的api响应(计算机上的普通请求)以确保按预期工作。如果是,请调试传递给Arduino / ESP代码中的JSON对象的字符串如何连接(如果所有数据都以正确的顺序排列等)。
答案 1 :(得分:0)
好的,我找到了问题的答案。有点.. 最后,我注意到api的响应从未完成。 所以解析可能从来没有奏效。