热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

Arduinojson官网序列化示例教程

Arduinojson官网序列化示例教程Arduinojson官方示例程序:#includevoidsetup(){Initializ

Arduinojson官网序列化示例教程


  • Arduinojson官方示例程序:

#include void setup() {// Initialize Serial portSerial.begin(9600);while (!Serial) continue;// Allocate the JSON document//// Inside the brackets, 200 is the RAM allocated to this document.// Don&#39;t forget to change this value to match your requirement.// Use arduinojson.org/v6/assistant to compute the capacity.StaticJsonDocument<200> doc;// StaticJsonObject allocates memory on the stack, it can be// replaced by DynamicJsonDocument which allocates in the heap.//// DynamicJsonDocument doc(200);// Add values in the document//doc["sensor"] &#61; "gps";doc["time"] &#61; 1351824120;// Add an array.//JsonArray data &#61; doc.createNestedArray("data");data.add(48.756080);data.add(2.302038);// Generate the minified JSON and send it to the Serial port.//serializeJson(doc, Serial);// The above line prints:// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}// Start a new lineSerial.println();// Generate the prettified JSON and send it to the Serial port.//serializeJsonPretty(doc, Serial);// The above line prints:// {// "sensor": "gps",// "time": 1351824120,// "data": [// 48.756080,// 2.302038// ]// }
}void loop() {// not used in this example
}

  • 串口打印信息
    在这里插入图片描述

推荐阅读
author-avatar
Gemini强强Gemini
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有