Arduino 处理JSON格式的数据

 

1、安装 ArduinoJson这个包

2、程序代码

# include <ArduinoJson.h>

#define ALINK_BODY_FORMAT "{\"id\":\"123\",\"version123\":\"1.0\",\"method\":\"thing.event.property.post\",\"params\":%s}"

void setup() {
  // 将 ALINK_BODY_FORMAT 替换成你想处理的字符串
  DynamicJsonDocument doc(1024);
  deserializeJson(doc, ALINK_BODY_FORMAT);
  JsonObject obj = doc.as<JsonObject>();
  
  Serial.begin(115200);
  String my_method = obj["method"];
  // my_method = obj["method"].as<String>();
  Serial.println(my_method);

  String no_param = obj["no"];
  Serial.println(no_param);
  if (no_param == "null") {
    Serial.println("NO PARAM");
  }
  if (no_param != "null") {
    Serial.println("NOT NO PARAM");
  }
}

void loop() {
  // put your main code here, to run repeatedly:

}

 

 

相关文章:

  • 2021-12-03
  • 2021-09-19
  • 2021-12-16
  • 2022-12-23
  • 2021-11-16
  • 2021-09-29
  • 2021-04-17
猜你喜欢
  • 2022-12-23
  • 2021-09-19
  • 2021-07-27
  • 2022-12-23
  • 2021-11-04
  • 2022-02-09
  • 2021-12-22
相关资源
相似解决方案