使用ArduinoJson

时间:2018-08-08 09:42:40

标签: arduino esp8266 nodemcu

我正在尝试使用ESP8266 NodeMCU v3解析JSON消息,这是代码:

// Robo India Tutorial 
// Digital Input and Output on LED 
// Hardware: NodeMCU
#include <ArduinoJson.h>
const int transistor = 16;  // Assigning name to Trasistor 

void setup() {                
   Serial.begin(9600);
}

void loop() {
  String payload;
  payload = "{\"update\":true,\"waitetime\":[[\"1\",\"-1\",\"-1\",\"287\",\"287\",\"287\",\"748\",\"575\",\"575\",\"988\",\"1036\",\"863\",\"1151\",\"1151\",\"1151\",\"1439\",\"1439\",\"1439\",\"1727\",\"1727\",\"1727\",\"2017\",\"2015\",\"2015\",\"2303\",\"2303\",\"2303\",\"2764\",\"2591\",\"2591\",\"3004\",\"3052\",\"2879\",\"3167\",\"3167\",\"3167\",\"3455\",\"3455\",\"3455\",\"3743\",\"3743\",\"3743\",\"4033\",\"4031\",\"4031\",\"4319\",\"4319\",\"4319\",\"4780\",\"4607\",\"4607\",\"5020\",\"5068\",\"4895\",\"5183\",\"5183\",\"5183\",\"5471\",\"5471\",\"5471\",\"5759\",\"5759\",\"5759\",\"6049\",\"6047\",\"6047\",\"6335\",\"6335\",\"6335\",\"6796\",\"6623\",\"6623\",\"7036\",\"7084\",\"6911\",\"7199\",\"7199\",\"7199\",\"7487\",\"7487\",\"7487\",\"7775\",\"7775\",\"7775\",\"8065\",\"8063\",\"8063\",\"8351\",\"8351\",\"8351\"]],\"duration\":[[\"3\",\"0\",\"0\",\"0\",\"0\",\"0\",\"12\",\"0\",\"0\",\"2\",\"6\",\"0\",\"8\",\"0\",\"0\",\"6\",\"0\",\"0\",\"6\",\"0\",\"0\",\"3\",\"0\",\"0\",\"0\",\"0\",\"0\",\"12\",\"0\",\"0\",\"2\",\"6\",\"0\",\"8\",\"0\",\"0\",\"6\",\"0\",\"0\",\"6\",\"0\",\"0\",\"3\",\"0\",\"0\",\"0\",\"0\",\"0\",\"12\",\"0\",\"0\",\"2\",\"6\",\"0\",\"8\",\"0\",\"0\",\"6\",\"0\",\"0\",\"6\",\"0\",\"0\",\"3\",\"0\",\"0\",\"0\",\"0\",\"0\",\"12\",\"0\",\"0\",\"2\",\"6\",\"0\",\"8\",\"0\",\"0\",\"6\",\"0\",\"0\",\"6\",\"0\",\"0\",\"3\",\"0\",\"0\",\"0\",\"0\",\"0\"]]}";
  StaticJsonBuffer<6000> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(payload)
  if (!root.success()) {
    Serial.println("Parsing fail");
  }   
  JsonArray& wt = root["waitetime"];
  Serial.println(wt[0][0].as<int>());
  delay(1000);               
}

我尝试使用Serial.println (root["update"]);Serial.println (root["waitetime"][0][0]);,并在串行监视器中得到它:

出什么问题了?

并且我尝试用JsonArray解析json消息以获取root [“ waitetime”]数据,但是它再次无法工作

0 个答案:

没有答案