YFROBOT创客社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 6861|回复: 2
打印 上一主题 下一主题

Arduino library -- JSON Library 使用

[复制链接]

签到天数: 866 天

[LV.10]以坛为家III

跳转到指定楼层
楼主
发表于 2016-8-22 11:01:47 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 AllBlue 于 2016-8-22 16:05 编辑

JSON Library 使用
JSON library github地址:github arduino Json
本站下载地址:
WIKI 简介地址
JSON 是什么?

看下josn 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.
翻译:
优雅和高效的JSON库为嵌入式系统。
它的设计有最直观的API ,最小的足迹和作品,而不在堆(没有malloc)任何分配。
它已被写入与Arduino的想法,但它不挂的Arduino库,这样你就可以在任何其他C ++项目使用这个库。


解码/解析
[C++] 纯文本查看 复制代码
char json[] = "{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";

StaticJsonBuffer<200> jsonBuffer;

JsonObject& root = jsonBuffer.parseObject(json);

const char* sensor = root["sensor"];
long time          = root["time"];
double latitude    = root["data"][0];
double longitude   = root["data"][1];

看例程:
JsonParserExample  -- Json 解析例程
JsonHttpClient         -- Json HTTP Client例程(获取网络Json数据并解析)
JsonHttpClientWithESP8266 --


编码/生成
[C++] 纯文本查看 复制代码
StaticJsonBuffer<200> jsonBuffer;

JsonObject& root = jsonBuffer.createObject();
root["sensor"] = "gps";
root["time"] = 1351824120;

JsonArray& data = root.createNestedArray("data");
data.add(48.756080, 6);  // 6 is the number of decimals to print
data.add(2.302038, 6);   // if not specified, 2 digits are printed

root.printTo(Serial);
// This prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}

看例程:
JsonGeneratorExample  -- Json 生成例程
JsonServer                     -- Json Server例程(生成Json数据并发布)
JsonServerWithESP8266 --






本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 支持支持 反对反对

该用户从未签到

沙发
发表于 2018-9-9 13:51:21 | 只看该作者
新手报道,回复学习
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|联系我们|YFROBOT ( 苏ICP备20009901号-2  

GMT+8, 2024-5-3 06:40 , Processed in 0.045745 second(s), 26 queries .

Powered by Discuz! X3.1

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表