# cJSON
Ultralightweight JSON parser in ANSI C.
## Table of contents
* [License](#license)
* [Usage](#usage)
* [Welcome to cJSON](#welcome-to-cjson)
* [Building](#building)
* [Copying the source](#copying-the-source)
* [CMake](#cmake)
* [Makefile](#makefile)
* [Including cJSON](#including-cjson)
* [Data Structure](#data-structure)
* [Working with the data structure](#working-with-the-data-structure)
* [Basic types](#basic-types)
* [Arrays](#arrays)
* [Objects](#objects)
* [Parsing JSON](#parsing-json)
* [Printing JSON](#printing-json)
* [Example](#example)
* [Printing](#printing)
* [Parsing](#parsing)
* [Caveats](#caveats)
* [Zero Character](#zero-character)
* [Character Encoding](#character-encoding)
* [C Standard](#c-standard)
* [Floating Point Numbers](#floating-point-numbers)
* [Deep Nesting Of Arrays And Objects](#deep-nesting-of-arrays-and-objects)
* [Thread Safety](#thread-safety)
* [Case Sensitivity](#case-sensitivity)
* [Duplicate Object Members](#duplicate-object-members)
* [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, GCC and MSVC). 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)
* `-DENABLE_SAFE_STACK`: Enable the [SafeStack](https://clang.llvm.org/docs/SafeStack.html) instrumentation pass. Currently only works with the Clang compiler. (off by default)
* `-DBUILD_SHARED_LIBS=On`: Build the shared libraries. (on by default)
* `-DBUILD_SHARED_AND_STATIC_LIBS=On`: Build both shared and static libraries. (off by default)
* `-DCMAKE_INSTALL_PREFIX=/usr`: Set a prefix for the installation.
* `-DENABLE_LOCALES=On`: Enable the usage of localeconv method. ( on by default )
* `-DCJSON_OVERRIDE_BUILD_SHARED_LIBS=On`: Enable overriding the value of `BUILD_SHARED_LIBS` with `-DCJSON_BUILD_SHARED_LIBS`.
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
```
On Windows CMake is usually used to create a Visual Studio solution file by running it inside the Developer Command Prompt for Visual Studio, for exact steps follow the official documentation from CMake and Microsoft and use the online search engine of your choice. The descriptions of the the options above still generally apply, although not all of them work on Windows.
#### Makefile
**NOTE:** This Method is deprecated. Use CMake if at all possible. Makefile support is limited to fixing bugs.
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 (not the full test suite).
```
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`.
### Including cJSON
If you installed it via CMake or the Makefile, you can include cJSON like this:
```c
#include <cjson/cJSON.h>
```
### Data Structure
cJSON represents JSON data using the `cJSON` struct data type:
```c
/* The cJSON structure: */
typedef struct cJSON
{
struct cJSON *next;
struct cJSON *prev;
struct cJSON *child;
int type;
char *valuestring;
/* writing to valueint is DEPRECATED, use cJSON_SetNumberValue instead */
int valueint;
double valuedouble;
char *string;
} cJSON;
```
An item of this type represents a JSON value. The type is stored in `type` as a bit-flag (**this means that you cannot find out the type by just comparing the value of `type`**).
To check the type of an item, use the correspo
没有合适的资源?快使用搜索试试~ 我知道了~
【例程】OneOS启物开发板板级支持包(BSP)
共2000个文件
c:3198个
h:2885个
d:960个
需积分: 16 2 下载量 7 浏览量
2022-08-31
20:43:07
上传
评论
收藏 48.23MB 7Z 举报
温馨提示
本板级支持包(BSP)是基于OneOS官方源码进行二次开发,对本开发板进行适配,方便使用与学习开发的一个源码项目。主要针对中国移动OneOS 启物开发板<以下简称启物开发板>进行更新优化。
资源详情
资源评论
资源推荐
收起资源包目录
【例程】OneOS启物开发板板级支持包(BSP) (2000个子文件)
lv_demo_printer_img_scan_example.c 9.14MB
lv_demo_printer_img_btn_bg_4.c 1.93MB
lv_demo_printer_img_btn_bg_1.c 1.93MB
lv_demo_printer_img_btn_bg_3.c 1.93MB
lv_demo_printer_img_btn_bg_2.c 1.93MB
unicode.c 1.9MB
lv_demo_printer_img_ready.c 1.72MB
img_lv_demo_music_cover_1.c 1.59MB
img_lv_demo_music_cover_2.c 1.59MB
img_lv_demo_music_cover_3.c 1.59MB
lv_demo_printer_img_printer2.c 785KB
img_cogwheel_argb.c 705KB
lv_font_simsun_16_cjk.c 610KB
img_lv_demo_music_wave_bottom.c 604KB
img_lv_demo_music_wave_top.c 604KB
lv_font_montserrat_48.c 562KB
lv_demo_printer_img_phone.c 538KB
lv_font_montserrat_46.c 530KB
img_cogwheel_chroma_keyed.c 530KB
img_cogwheel_rgb.c 529KB
img_lv_demo_music_logo.c 498KB
lv_font_montserrat_44.c 486KB
lv_font_montserrat_42.c 449KB
img_lv_demo_music_btn_pause.c 430KB
img_lv_demo_music_btn_play.c 430KB
lv_font_montserrat_40.c 410KB
uws_client_ut.c 404KB
lv_demo_printer_img_cloud.c 388KB
lv_font_montserrat_38.c 371KB
imgbtn_green.c 353KB
imgbtn_blue.c 353KB
lv_font_montserrat_36.c 337KB
ssl_tls.c 315KB
lv_font_montserrat_34.c 307KB
lv_demo_printer_img_internet.c 294KB
lv_demo_printer_img_print.c 294KB
lv_demo_printer_img_setup.c 285KB
lv_font_dejavu_16_persian_hebrew.c 278KB
img_lv_demo_music_btn_prev.c 272KB
img_lv_demo_music_btn_next.c 272KB
lv_font_montserrat_32.c 271KB
lv_demo_printer_img_usb.c 268KB
schema_ut.c 268KB
nghttp2_session.c 253KB
lv_font_montserrat_30.c 248KB
img_lv_demo_music_btn_list_pause.c 246KB
img_lv_demo_music_btn_list_play.c 246KB
ff.c 244KB
ssl_tls.c 240KB
psa_crypto.c 237KB
commanddecoder_ut.c 233KB
lv_font_montserrat_28.c 221KB
lv_demo_printer_img_scan.c 221KB
lv_demo_printer_img_copy.c 217KB
codefirst_ut.c 213KB
lv_demo_printer_img_mobile.c 213KB
ssl_msg.c 203KB
ff.c 198KB
lv_font_montserrat_26.c 196KB
httpapicompact_ut.c 181KB
http_proxy_io_ut.c 179KB
lv_font_montserrat_24.c 172KB
ble_sm_sc_test.c 168KB
ble_gap.c 166KB
ssl_srv.c 162KB
agenttypesystem.c 160KB
ble_ll_adv.c 158KB
httpapiex_ut.c 158KB
serializer_int.c 157KB
lv_font_montserrat_22.c 153KB
lv_obj.c 153KB
ssl_cli.c 151KB
ssl_srv.c 150KB
ble_ll_conn.c 148KB
lfs2.c 146KB
schema.c 144KB
compile.c 143KB
lv_font_montserrat_28_compressed.c 138KB
wsio_ut.c 138KB
map_ut.c 137KB
sockets.c 136KB
cmd.c 136KB
ble_gattc.c 135KB
lv_font_montserrat_20.c 132KB
ssl_cli.c 127KB
uws_client.c 126KB
lv_demo_printer_img_no_internet.c 126KB
HAL_tim.c 125KB
iot_tests_mqtt_api.c 121KB
HAL_tim.c 121KB
HAL_tim.c 121KB
emitnative.c 119KB
ble_ll_scan.c 118KB
mqtt_client_ut.c 118KB
HAL_tim.c 117KB
HAL_tim.c 117KB
HAL_tim.c 117KB
HAL_tim.c 117KB
lv_font_montserrat_18.c 116KB
lv_demo_printer_icon_wifi.c 116KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
2345VOR
- 粉丝: 3w+
- 资源: 62
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0