0
ArduinoでHTTPメソッドを使用してJSONデータを取得し、Stringオブジェクトに格納しています。データは次のとおりです。JSONデータを文字列から解析する
{
"item": {
"Identity": {
"Id": "327681",
"ItemId": "64006A962B71A1E7B3A0428637DA997C.327681",
"Level": 1,
"EntityType": "64006A962B71A1E7B3A0428637DA997C",
"ItemStatus": 1
},
"Properties": {
"AssetName": "PHE-1001",
"Category": "Electrical Appliance",
"RegistrationTime": "2017-12-14Z",
"Activated": true,
"Status": "Offline",
"Manufacturer": "Philips",
"ModelNumber": "1E-S00ER11",
"SerialNumber": "YGTJGJK458545",
"sample_property": null,
"AssetLocation": null,
"AssetType": null,
"ActivationTime": "2017-12-24T05:44:38Z",
"Country": "India",
"PostalAddress": "500081",
"dummy": null,
"TotalHours": 16,
"TotalWorkingHoursFromInstallation": 38,
"TotalLifeTime": 62,
"AssetSensorDistance": null
}
}
}
Arduinoのコード:
HTTPClient http;
http.begin("URL");
int httpCode = http.GET(); // //Send the request
if (httpCode == 200) {
String payload = http.getString();
Serial.println(payload);
}
は、今私が唯一AssetName
、Status
とAssetSensorDistance
を取得したいです。私はpayload["Status"]
を試しましたが、何も印刷しません。
誰もがこれを手伝ってくれますか?前もって感謝します。
StaticJsonBuffer <200> jsonBuffer; JsonObject&root = jsonBuffer.parseObject(ペイロード); if(!root.success()) { Serial.println( "Parsing Failed"); } 「解析が失敗しました」と表示されています –
入力バッファーが小さすぎます。少なくとも842バイト必要です。 http://arduinojson.org/faq/why-parsing-fails/と、この本当にクールなツールhttp://arduinojson.org/assistant/を参照してください。 Btwは "ArduinoJsonの解析に失敗しました"というグーグルでそれを手に入れました... Googleはあなたの友人です:-) – Yaro