Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 29-Oct-2021 | - | ||||
example/ | 29-Oct-2021 | - | ||||
include/ | 29-Oct-2021 | - | ||||
src/ | 29-Oct-2021 | - | ||||
README.md | A D | 29-Oct-2021 | 6.3 KiB | 197 | 149 | |
package.yaml | A D | 29-Oct-2021 | 4 KiB |
README.md
1@page cjson cjson 2 3[更正文档](https://gitee.com/alios-things/cjson/edit/master/README.md)      [贡献说明](https://help.aliyun.com/document_detail/302301.html) 4 5# 概述 6cJSON是符合ANSI C标准的极轻量级JSON解析器。 7 8## 版权说明 9> The MIT License 10 11## 目录结构 12``` 13├── src 14│ ├── cJSON.c # 源文件(必需) 15│ └── cJPath.c # 源文件(必需) 16├── include 17│ └── cJSON.h # 包含cJSON API 18├── package.yaml # 编译配置文件 19└── example 20 └── cjson_example.c # 示例代码(默认禁用,可在package.yaml中使能) 21``` 22 23## 依赖组件 24* osal_aos 25 26# 常用配置 27无 28 29# API说明 30 31## 将字符串解析为JSON结构体 32```c 33cJSON *cJSON_Parse(const char *value); 34``` 35|args |description| 36|:----- |:----| 37|value |JSON字符串| 38 39## 删除JSON结构体 40```c 41void cJSON_Delete(cJSON *c); 42``` 43|args |description| 44|:----- |:----| 45|value |待删除的JSON结构体| 46 47## 获取JSON数组包含成员个数 48```c 49int cJSON_GetArraySize(const cJSON *array); 50``` 51|args |description| 52|:----- |:----| 53|value |数组类型的JSON结构体| 54 55## 获取JSON数组成员 56```c 57cJSON *cJSON_GetArrayItem(const cJSON *array, int index); 58``` 59|args |description| 60|:----- |:----| 61|array |数组类型的JSON结构体| 62|index |数组成员索引| 63 64## 获取JSON对象成员 65```c 66cJSON *cJSON_GetObjectItemCaseSensitive(const cJSON * const object, const char * const string); 67``` 68|args |description| 69|:----- |:----| 70|object |对象类型的JSON结构体| 71|string |成员名称(大小写敏感)| 72 73## 获取出错信息 74```c 75const char *cJSON_GetErrorPtr(void); 76``` 77 78## 判断JSON结构体是否为布尔类型 79```c 80cJSON_bool cJSON_IsBool(const cJSON * const item); 81``` 82|args |description| 83|:----- |:----| 84|item |待判断的JSON结构体| 85 86## 判断JSON结构体是否为数值类型 87```c 88cJSON_bool cJSON_IsNumber(const cJSON * const item); 89``` 90|args |description| 91|:----- |:----| 92|item |待判断的JSON结构体| 93 94## 判断JSON结构体是否为字符串类型 95```c 96cJSON_bool cJSON_IsString(const cJSON * const item); 97``` 98|args |description| 99|:----- |:----| 100|item |待判断的JSON结构体| 101 102## 判断JSON结构体是否为数组类型 103```c 104cJSON_bool cJSON_IsArray(const cJSON * const item); 105``` 106|args |description| 107|:----- |:----| 108|item |待判断的JSON结构体| 109 110## 判断JSON结构体是否为对象类型 111```c 112cJSON_bool cJSON_IsObject(const cJSON * const item); 113``` 114|args |description| 115|:----- |:----| 116|item |待判断的JSON结构体| 117 118# 使用示例 119 120组件使用示例相关的代码下载、编译和固件烧录均依赖AliOS Things配套的开发工具,所以首先需要参考[《AliOS Things集成开发环境使用说明之搭建开发环境》](https://help.aliyun.com/document_detail/302378.html),下载安装。 121待开发环境搭建完成后,可以按照以下步骤进行示例的测试。 122 123## 步骤1 创建或打开工程 124 125**打开已有工程** 126 127如果用于测试的案例工程已存在,可参考[《AliOS Things集成开发环境使用说明之打开工程》](https://help.aliyun.com/document_detail/302381.html)打开已有工程。 128 129**创建新的工程** 130 131组件的示例代码可以通过编译链接到AliOS Things的任意案例(solution)来运行,这里选择helloworld_demo案例。helloworld_demo案例相关的源代码下载可参考[《AliOS Things集成开发环境使用说明之创建工程》](https://help.aliyun.com/document_detail/302379.html)。 132 133## 步骤2 添加组件 134 135案例下载完成后,需要在helloworld_demo组件的package.yaml中添加对组件的依赖: 136```yaml 137depends: 138 - cjson: master 139``` 140 141## 步骤3 下载组件 142 143在已安装了 的开发环境工具栏中,选择Terminal -> New Terminal启动终端,并且默认工作路径为当前工程的workspace,此时在终端命令行中输入: 144 145```shell 146 147aos install cjson 148 149``` 150 151上述命令执行成功后,组件源码则被下载到了./components/cjson路径中。 152 153## 步骤4 添加示例 154 155在cjson组件的package.yaml中添加[example示例代码](https://gitee.com/alios-things/cjson/tree/master/example): 156``` 157source_file: 158 - "src/*.c" 159 - "example/cjson_example.c" 160``` 161 162## 步骤5 编译固件 163 164在示例代码已经添加至组件的配置文件,并且helloworld_demo已添加了对该组件的依赖后,就可以编译helloworld_demo案例来生成固件了,具体编译方法可参考[《AliOS Things集成开发环境使用说明之编译固件》](https://help.aliyun.com/document_detail/302384.html)。 165 166## 步骤6 烧录固件 167 168helloworld_demo案例的固件生成后,可参考[《AliOS Things集成开发环境使用说明之烧录固件》](https://help.aliyun.com/document_detail/302383.html)来烧录固件。 169 170## 步骤7 打开串口 171 172固件烧录完成后,可以通过串口查看示例的运行结果,打开串口的具体方法可参考[《AliOS Things集成开发环境使用说明之查看日志》](https://help.aliyun.com/document_detail/302382.html)。 173 174当串口终端打开成功后,可在串口中输入help来查看已添加的测试命令。 175 176## 步骤8 测试示例 177 178CLI命令行输入: 179``` 180cjson_example 181``` 182 183**关键日志** 184CLI日志: 185``` 186Checking monitor "Awesome 4K" 1871280 x 720.00 1881920 x 1080.00 1893840 x 2160.00 190``` 191 192# 注意事项 193无 194 195# FAQ 196无 197