“Json库”的版本间的差异
(未显示1个用户的4个中间版本) | |||
第1行: | 第1行: | ||
− | [http://www.json.org/json-zh.html JSON 介绍] | + | [http://www.json.org/json-zh.html JSON 介绍] |
− | library from [https://github.com/bblanchon/ArduinoJson github arduino Json] | + | |
+ | |||
+ | json library from [https://github.com/bblanchon/ArduinoJson github arduino Json] | ||
+ | |||
+ | [https://github.com/bblanchon/ArduinoJson/wiki Github arduino json wiki] | [http://www.yfrobot.com/thread-11875-1-1.html JSON Library 论坛简介贴地址] | ||
download from the address:[https://github.com/bblanchon/ArduinoJson/releases zip address] | download from the address:[https://github.com/bblanchon/ArduinoJson/releases zip address] | ||
第21行: | 第25行: | ||
<font color="orange" size="+2">'''Examples'''</font><br> | <font color="orange" size="+2">'''Examples'''</font><br> | ||
<br> | <br> | ||
− | :-[[ IndentedPrintExample]] : Indented Print | + | :-[[ IndentedPrintExample]] : Indented Print - 缩进打印例程 |
− | :-[[ JsonGeneratorExample]] : Json Generator | + | :-[[ JsonGeneratorExample]] : Json Generator - Json 生成例程 |
− | :-[[ JsonHttpClient]] : Json Http Client | + | :-[[ JsonHttpClient]] : Json Http Client - Json HTTP Client例程(获取网络Json数据并解析) |
− | :-[[ JsonParserExample]] : Json Parser | + | :-[[ JsonParserExample]] : Json Parser - Json 解析例程 |
− | :-[[ JsonServer]] : Json Server | + | :-[[ JsonServer]] : Json Server - Json Server例程(生成Json数据并发布) |
− | :-[[ JsonUdpBeacon]] : Json Udp Beacon | + | :-[[ JsonUdpBeacon]] : Json Udp Beacon - Json UDP Beacon 例程 |
+ | <font color="orange" size="+2">'''Extra Examples'''</font><br> | ||
− | + | :-[http://www.yfrobot.com/forum.php?mod=attachment&aid=MTU2NnxiNTY4OWQ1OXwxNDcxODQ4NzUxfDJ8MTE4NzU%3D JsonHttpClientWithESP8266] : Json Http Client With ESP8266 - Json HTTP Client例程(获取网络Json数据并解析) | |
− | + | ||
− | |width=" | + | :-[http://www.yfrobot.com/forum.php?mod=attachment&aid=MTU2OHwxZTQ2MmIxMnwxNDcxODQ4NzUxfDJ8MTE4NzU%3D JsonServerWithESP8266] : Json Server With ESP8266 - Json Server例程(生成Json数据并发布) |
+ | |||
+ | |||
+ | <!-- |width="10%" valign="top" align="left"| | ||
+ | 空白 --> | ||
+ | |||
+ | |width="40%" valign="top" align="left"| | ||
<br> | <br> | ||
− | <font color="orange" size="+2">''' | + | <font color="orange" size="+2">'''Json Library Reference'''</font><br><br> |
+ | |||
+ | - <font color="forestgreen">StaticJsonBuffer<200> jsonBuffer;</font> | ||
+ | |||
+ | 为JSON对象树创建内存池(在栈上分配内存) | ||
+ | |||
+ | 参数 | ||
+ | :200:内存大小(字节) -根据对象大小更改 | ||
+ | |||
+ | - <font color="forestgreen">DynamicJsonBuffer jsonBuffer;</font> | ||
+ | |||
+ | 为JSON对象树创建内存池(在堆上分配内存)- 简单但效率低 | ||
+ | |||
+ | |||
+ | ---- | ||
+ | |||
+ | |||
+ | - <font color="forestgreen">JsonObject& root = jsonBuffer.createObject();</font> | ||
+ | |||
+ | 创建对象树的根 | ||
+ | |||
+ | - <font color="forestgreen">root["sensor"] = "gps";</font> | ||
+ | |||
+ | 在对象中添加值 | ||
+ | |||
+ | 参数 | ||
+ | :sensor:名称 | ||
+ | :gps:值 | ||
+ | |||
+ | - <font color="forestgreen">JsonArray& data = root.createNestedArray("data");</font> | ||
+ | |||
+ | 在对象中添加一个嵌套的数组 | ||
+ | |||
+ | 参数 | ||
+ | :data:数组名 | ||
+ | |||
+ | - <font color="forestgreen">data.add(double_with_n_digits(48.756080, 6));</font> | ||
+ | |||
+ | 给data数组添加值 | ||
+ | |||
+ | 参数 | ||
+ | :48756080:值 | ||
+ | :6:保留小数位数 | ||
+ | |||
+ | - <font color="forestgreen">root.printTo(Serial);</font> | ||
+ | |||
+ | 打印输出 | ||
+ | |||
+ | 参数 | ||
+ | :48756080:值 | ||
+ | |||
+ | 例:{"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]} | ||
+ | |||
+ | |||
+ | - <font color="forestgreen">root.prettyPrintTo(Serial);</font> | ||
+ | |||
+ | 打印输出(格式) | ||
+ | |||
+ | ---- | ||
− | |||
− | + | - <font color="forestgreen">JsonObject& root = jsonBuffer.parseObject(json);</font> | |
− | + | 解析json数据 | |
− | + | - <font color="forestgreen">sensor = root["sensor"]</font> | |
− | + | 取值 | |
− | + | - <font color="forestgreen">latitude = root["data"][0];</font> | |
+ | "data":[48.756080,2.302038] | ||
− | + | 取值 | |
<br> | <br> |
2016年8月23日 (二) 08:07的最后版本
json library from github arduino Json
Github arduino json wiki | JSON Library 论坛简介贴地址
download from the address:zip address
Welcome to the user manual for the Arduino JSON library, an elegant and efficient JSON library for embedded systems. It's designed to have the most intuitive API, the smallest footprint and works without any allocation on the heap (no malloc). It has been written with Arduino in mind, but it isn't linked to Arduino libraries so you can use this library in any other C++ project. Using the library with Arduino
Examples
Extra Examples
|
- StaticJsonBuffer<200> jsonBuffer; 为JSON对象树创建内存池(在栈上分配内存) 参数
- DynamicJsonBuffer jsonBuffer; 为JSON对象树创建内存池(在堆上分配内存)- 简单但效率低
创建对象树的根 - root["sensor"] = "gps"; 在对象中添加值 参数
- JsonArray& data = root.createNestedArray("data"); 在对象中添加一个嵌套的数组 参数
- data.add(double_with_n_digits(48.756080, 6)); 给data数组添加值 参数
- root.printTo(Serial); 打印输出 参数
例:{"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
打印输出(格式)
解析json数据 - sensor = root["sensor"] 取值 - latitude = root["data"][0]; "data":[48.756080,2.302038] 取值
|
更多建议和问题欢迎反馈至 YFRobot论坛