# cJSON
Ultralightweight JSON parser in ANSI C.
## Table of contents
* [License](#license)
* [Usage](#usage)
* [Welcome to cJSON](#welcome-to-cjson)
* [Building](#building)
* [Some JSON](#some-json)
* [Here's the structure](#heres-the-structure)
* [Caveats](#caveats)
* [Enjoy cJSON!](#enjoy-cjson)
## License
MIT License
> Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
## Usage
### Welcome to cJSON.
cJSON aims to be the dumbest possible parser that you can get your job done with.
It's a single file of C, and a single header file.
JSON is described best here: http://www.json.org/
It's like XML, but fat-free. You use it to move data around, store things, or just
generally represent your program's state.
As a library, cJSON exists to take away as much legwork as it can, but not get in your way.
As a point of pragmatism (i.e. ignoring the truth), I'm going to say that you can use it
in one of two modes: Auto and Manual. Let's have a quick run-through.
I lifted some JSON from this page: http://www.json.org/fatfree.html
That page inspired me to write cJSON, which is a parser that tries to share the same
philosophy as JSON itself. Simple, dumb, out of the way.
### Building
There are several ways to incorporate cJSON into your project.
#### copying the source
Because the entire library is only one C file and one header file, you can just copy `cJSON.h` and `cJSON.c` to your projects source and start using it.
cJSON is written in ANSI C (C89) in order to support as many platforms and compilers as possible.
#### CMake
With CMake, cJSON supports a full blown build system. This way you get the most features. CMake with an equal or higher version than 2.8.5 is supported. With CMake it is recommended to do an out of tree build, meaning the compiled files are put in a directory separate from the source files. So in order to build cJSON with CMake on a Unix platform, make a `build` directory and run CMake inside it.
```
mkdir build
cd build
cmake ..
```
This will create a Makefile and a bunch of other files. You can then compile it:
```
make
```
And install it with `make install` if you want. By default it installs the headers `/usr/local/include/cjson` and the libraries to `/usr/local/lib`. It also installs files for pkg-config to make it easier to detect and use an existing installation of CMake. And it installs CMake config files, that can be used by other CMake based projects to discover the library.
You can change the build process with a list of different options that you can pass to CMake. Turn them on with `On` and off with `Off`:
* `-DENABLE_CJSON_TEST=On`: Enable building the tests. (on by default)
* `-DENABLE_CJSON_UTILS=On`: Enable building cJSON_Utils. (off by default)
* `-DENABLE_TARGET_EXPORT=On`: Enable the export of CMake targets. Turn off if it makes problems. (on by default)
* `-DENABLE_CUSTOM_COMPILER_FLAGS=On`: Enable custom compiler flags (currently for Clang and GCC). Turn off if it makes problems. (on by default)
* `-DENABLE_VALGRIND=On`: Run tests with [valgrind](http://valgrind.org). (off by default)
* `-DENABLE_SANITIZERS=On`: Compile cJSON with [AddressSanitizer](https://github.com/google/sanitizers/wiki/AddressSanitizer) and [UndefinedBehaviorSanitizer](https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html) enabled (if possible). (off by default)
* `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
If you are packaging cJSON for a distribution of Linux, you would probably take these steps for example:
```
mkdir build
cd build
cmake .. -DENABLE_CJSON_UTILS=On -DENABLE_CJSON_TEST=Off -DCMAKE_INSTALL_PREFIX=/usr
make
make DESTDIR=$pkgdir install
```
#### Makefile
If you don't have CMake available, but still have GNU make. You can use the makefile to build cJSON:
Run this command in the directory with the source code and it will automatically compile static and shared libraries and a little test program.
```
make all
```
If you want, you can install the compiled library to your system using `make install`. By default it will install the headers in `/usr/local/include/cjson` and the libraries in `/usr/local/lib`. But you can change this behavior by setting the `PREFIX` and `DESTDIR` variables: `make PREFIX=/usr DESTDIR=temp install`.
### Some JSON:
```json
{
"name": "Jack (\"Bee\") Nimble",
"format": {
"type": "rect",
"width": 1920,
"height": 1080,
"interlace": false,
"frame rate": 24
}
}
```
Assume that you got this from a file, a webserver, or magic JSON elves, whatever,
you have a `char *` to it. Everything is a `cJSON` struct.
Get it parsed:
```c
cJSON * root = cJSON_Parse(my_json_string);
```
This is an object. We're in C. We don't have objects. But we do have structs.
What's the framerate?
```c
cJSON *format = cJSON_GetObjectItemCaseSensitive(root, "format");
cJSON *framerate_item = cJSON_GetObjectItemCaseSensitive(format, "frame rate");
double framerate = 0;
if (cJSON_IsNumber(framerate_item))
{
framerate = framerate_item->valuedouble;
}
```
Want to change the framerate?
```c
cJSON *framerate_item = cJSON_GetObjectItemCaseSensitive(format, "frame rate");
cJSON_SetNumberValue(framerate_item, 25);
```
Back to disk?
```c
char *rendered = cJSON_Print(root);
```
Finished? Delete the root (this takes care of everything else).
```c
cJSON_Delete(root);
```
That's AUTO mode. If you're going to use Auto mode, you really ought to check pointers
before you dereference them. If you want to see how you'd build this struct in code?
```c
cJSON *root;
cJSON *fmt;
root = cJSON_CreateObject();
cJSON_AddItemToObject(root, "name", cJSON_CreateString("Jack (\"Bee\") Nimble"));
cJSON_AddItemToObject(root, "format", fmt = cJSON_CreateObject());
cJSON_AddStringToObject(fmt, "type", "rect");
cJSON_AddNumberToObject(fmt, "width", 1920);
cJSON_AddNumberToObject(fmt, "height", 1080);
cJSON_AddFalseToObject (fmt, "interlace");
cJSON_AddNumberToObject(fmt, "frame rate", 24);
```
Hopefully we can agree that's not a lot of code? There's no overhead, no unnecessary setup.
Look at `test.c` for a bunch of nice examples, mostly all ripped off the [json.org](http://json.org) site, and
a few from elsewhere.
What about manual mode? First up you need some detail.
Let's cover how the `cJSON` objects represent the JSON data.
cJSON doesn't distinguish arrays from objects in handling; just type.
Each `cJSON` has, potentially, a child, siblings, value, a name.
* The `root` object has: *Object* Type and a Child
* The Child has name "name", with value "Jack ("Bee") Nimble", and a sibling:
* Sibling has type *Object*, name "format", and a child.
* That child has type *String*, name "type", value "rect", and a sibling:
* Sibling has type *Number*, name "width", value 1920, and a sibling:
* Sibling has type
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
基于STM32的智能家居系统,运用贝壳物联服务器。主要模块包括ESP8266、DTH11、烟雾传感器、红外传感器、蜂鸣器组成。其中DTH11检测环境温湿度,烟雾传感器检测是否有着火现象,红外传感器检测是否有人异常闯入,通过蜂鸣器报警和通过邮箱等通知用户。.zip嵌入式优质项目,资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松copy复刻,拿到资料包后可轻松复现出一样的项目。 本人单片机开发经验充足,深耕嵌入式领域,有任何使用问题欢迎随时与我联系,我会及时为你解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明,项目具体内容可查看下方的资源详情。 【附带帮助】: 若还需要嵌入式物联网单片机相关领域开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步。 【本人专注嵌入式领域】: 有任何使用问题欢迎随时与我联系,我会及时解答,第一时间为你提供帮助,CSDN博客端可私信,为你解惑,欢迎交流。 【建议小白】: 在所有嵌入式开发中硬件部分若不会画PCB/电路,可选择根据引脚定义将其代替为面包板+杜邦线+外设模块的方式,只需轻松简单连线,下载源码烧录进去便可轻松复刻出一样的项目 【适合场景】: 相关项目设计中,皆可应用在项目开发、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面中 可借鉴此优质项目实现复刻,也可以基于此项目进行扩展来开发出更多功能
资源推荐
资源详情
资源评论
收起资源包目录
基于STM32+ESP8266设计的物联网智能家居系统(毕设/课设/竞赛/实训/项目开发) (274个子文件)
BH-STM32.uvguix.Administrator 92KB
智能家居.axf 401KB
keilkill.bat 374B
stm32f10x_tim.c 104KB
cJSON.c 64KB
stm32f10x_flash.c 59KB
stm32f10x_rcc.c 49KB
stm32f10x_adc.c 45KB
stm32f10x_i2c.c 43KB
stm32f10x_can.c 43KB
stm32f10x_usart.c 36KB
system_stm32f10x.c 35KB
stm32f10x_fsmc.c 34KB
stm32f10x_spi.c 29KB
stm32f10x_dma.c 28KB
stm32f10x_sdio.c 27KB
stm32f10x_gpio.c 22KB
stm32f10x_dac.c 18KB
core_cm3.c 16KB
OLED.c 13KB
stm32f10x_cec.c 11KB
stm32f10x_pwr.c 8KB
stm32f10x_rtc.c 8KB
stm32f10x_bkp.c 8KB
stepmotor.c 8KB
stm32f10x_exti.c 7KB
usart3.c 7KB
misc.c 7KB
main.c 6KB
stm32f10x_it.c 6KB
stm32f10x_wwdg.c 5KB
stm32f10x_dbgmcu.c 5KB
ADC.c 5KB
stm32f10x_iwdg.c 5KB
bsp_dht11.c 4KB
millis.c 4KB
math_display.c 4KB
Infrare.c 3KB
LED.c 3KB
stm32f10x_crc.c 3KB
yun.c 2KB
smoke.c 2KB
bsp_led.c 2KB
floatTOs.c 2KB
bsp_SysTick.c 1KB
all_init.c 1KB
bsp_beep.c 849B
stm32f10x_tim.crf 361KB
main.crf 358KB
bsp_esp8266.crf 353KB
test.crf 353KB
stm32f10x_it.crf 350KB
stm32f10x_can.crf 348KB
stepmotor.crf 347KB
yun.crf 346KB
stm32f10x_adc.crf 346KB
stm32f10x_rcc.crf 346KB
stm32f10x_flash.crf 346KB
stm32f10x_i2c.crf 345KB
oled.crf 345KB
stm32f10x_usart.crf 345KB
stm32f10x_fsmc.crf 345KB
usart3.crf 345KB
all_init.crf 344KB
bsp_usart.crf 344KB
stm32f10x_sdio.crf 343KB
stm32f10x_spi.crf 343KB
stm32f10x_gpio.crf 343KB
stm32f10x_dma.crf 342KB
math_display.crf 342KB
stm32f10x_dac.crf 341KB
stm32f10x_cec.crf 341KB
bsp_dht11.crf 341KB
system_stm32f10x.crf 340KB
stm32f10x_bkp.crf 340KB
stm32f10x_pwr.crf 340KB
stm32f10x_rtc.crf 340KB
stm32f10x_exti.crf 340KB
common.crf 340KB
bsp_led.crf 340KB
led.crf 340KB
floattos.crf 339KB
infrare.crf 339KB
adc.crf 339KB
stm32f10x_wwdg.crf 339KB
misc.crf 339KB
millis.crf 339KB
smoke.crf 339KB
delay.crf 339KB
stm32f10x_iwdg.crf 339KB
bsp_systick.crf 339KB
stm32f10x_crc.crf 339KB
bsp_beep.crf 339KB
stm32f10x_dbgmcu.crf 339KB
cjson.crf 56KB
core_cm3.crf 4KB
all_init.d 3KB
stm32f10x_it.d 3KB
main.d 3KB
bsp_esp8266.d 2KB
共 274 条
- 1
- 2
- 3
资源评论
- 2301_774807192024-05-14资源很实用,内容详细,值得借鉴的内容很多,感谢分享。
阿齐Archie
- 粉丝: 3w+
- 资源: 2474
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于flink的实时数仓详细文档+全部资料.zip
- 基于Flink的数据同步工具详细文档+全部资料.zip
- 基于Flink的数据流业务处理平台详细文档+全部资料.zip
- 基于flink的物流业务数据实时数仓建设详细文档+全部资料.zip
- 外卖时间数据,食品配送时间数据集,外卖影响因素数据集(千条数据)
- 基于flink的异构数据源同步详细文档+全部资料.zip
- 基于flink的营销系统详细文档+全部资料.zip
- 基于Flink对用户行为数据的实时分析详细文档+全部资料.zip
- 基于Flink分析用户行为详细文档+全部资料.zip
- 基于flink可以创建物理表的catalog详细文档+全部资料.zip
- 基于Flink流批一体数据处理快速集成开发框架、快速构建基于Java的Flink流批一体应用程序,实现异构数据库实时同步和ETL,还可以让Flink SQL变得
- 太和-圣德西实施—部门负责人以上宣贯培训大纲.doc
- 太和-圣德西实施—部门负责人非HR的HRM培训.pptx
- 太和-圣德西实施—宣贯培训大纲.docx
- 基于Flink流处理的动态实时亿级全端用户画像系统可视化界面详细文档+全部资料.zip
- 基于Flink全端用户画像商品推荐系统详细文档+全部资料.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功