Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
b2da44d6
T
Third Party CJSON
项目概览
OpenHarmony
/
Third Party CJSON
11 个月 前同步成功
通知
6
Star
22
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
Third Party CJSON
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b2da44d6
编写于
1月 09, 2017
作者:
M
Max Bruckner
提交者:
GitHub
1月 09, 2017
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #90 from DaveGamble/cJSON_Raw
Add support for raw JSON
上级
8893e397
f6998a6a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
1 deletion
+52
-1
CONTRIBUTORS.md
CONTRIBUTORS.md
+1
-0
cJSON.c
cJSON.c
+46
-0
cJSON.h
cJSON.h
+5
-1
未找到文件。
CONTRIBUTORS.md
浏览文件 @
b2da44d6
...
...
@@ -14,6 +14,7 @@ Contributors
*
Ian Mobley
*
Irwan Djadjadi
*
[
IvanVoid
](
https://github.com/npi3pak
)
*
[
Jiri Zouhar
](
https://github.com/loigu
)
*
[
Jonathan Fether
](
https://github.com/jfether
)
*
[
Kevin Branigan
](
https://github.com/kbranigan
)
*
[
Kyle Chisholm
](
https://github.com/ChisholmKyle
)
...
...
cJSON.c
浏览文件 @
b2da44d6
...
...
@@ -88,6 +88,11 @@ static char* cJSON_strdup(const char* str)
size_t
len
=
0
;
char
*
copy
=
NULL
;
if
(
str
==
NULL
)
{
return
NULL
;
}
len
=
strlen
(
str
)
+
1
;
if
(
!
(
copy
=
(
char
*
)
cJSON_malloc
(
len
)))
{
...
...
@@ -989,6 +994,27 @@ static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *
case
cJSON_Number
:
out
=
print_number
(
item
,
p
);
break
;
case
cJSON_Raw
:
{
size_t
raw_length
=
0
;
if
(
item
->
valuestring
==
NULL
)
{
if
(
!
p
->
noalloc
)
{
cJSON_free
(
p
->
buffer
);
}
out
=
NULL
;
break
;
}
raw_length
=
strlen
(
item
->
valuestring
)
+
sizeof
(
'\0'
);
out
=
ensure
(
p
,
raw_length
);
if
(
out
)
{
memcpy
(
out
,
item
->
valuestring
,
raw_length
);
}
break
;
}
case
cJSON_String
:
out
=
print_string
(
item
,
p
);
break
;
...
...
@@ -1016,6 +1042,9 @@ static char *print_value(const cJSON *item, int depth, cjbool fmt, printbuffer *
case
cJSON_Number
:
out
=
print_number
(
item
,
0
);
break
;
case
cJSON_Raw
:
out
=
cJSON_strdup
(
item
->
valuestring
);
break
;
case
cJSON_String
:
out
=
print_string
(
item
,
0
);
break
;
...
...
@@ -1988,6 +2017,23 @@ cJSON *cJSON_CreateString(const char *string)
return
item
;
}
extern
cJSON
*
cJSON_CreateRaw
(
const
char
*
raw
)
{
cJSON
*
item
=
cJSON_New_Item
();
if
(
item
)
{
item
->
type
=
cJSON_Raw
;
item
->
valuestring
=
cJSON_strdup
(
raw
);
if
(
!
item
->
valuestring
)
{
cJSON_Delete
(
item
);
return
NULL
;
}
}
return
item
;
}
cJSON
*
cJSON_CreateArray
(
void
)
{
cJSON
*
item
=
cJSON_New_Item
();
...
...
cJSON.h
浏览文件 @
b2da44d6
...
...
@@ -38,6 +38,7 @@ extern "C"
#define cJSON_String (1 << 4)
#define cJSON_Array (1 << 5)
#define cJSON_Object (1 << 6)
#define cJSON_Raw (1 << 7)
/* raw json */
#define cJSON_IsReference 256
#define cJSON_StringIsConst 512
...
...
@@ -54,7 +55,7 @@ typedef struct cJSON
/* The type of the item, as above. */
int
type
;
/* The item's string, if type==cJSON_String */
/* The item's string, if type==cJSON_String
and type == cJSON_Raw
*/
char
*
valuestring
;
/* The item's number, if type==cJSON_Number */
int
valueint
;
...
...
@@ -105,6 +106,8 @@ extern cJSON *cJSON_CreateFalse(void);
extern
cJSON
*
cJSON_CreateBool
(
int
b
);
extern
cJSON
*
cJSON_CreateNumber
(
double
num
);
extern
cJSON
*
cJSON_CreateString
(
const
char
*
string
);
/* raw json */
extern
cJSON
*
cJSON_CreateRaw
(
const
char
*
raw
);
extern
cJSON
*
cJSON_CreateArray
(
void
);
extern
cJSON
*
cJSON_CreateObject
(
void
);
...
...
@@ -155,6 +158,7 @@ extern void cJSON_Minify(char *json);
#define cJSON_AddBoolToObject(object,name,b) cJSON_AddItemToObject(object, name, cJSON_CreateBool(b))
#define cJSON_AddNumberToObject(object,name,n) cJSON_AddItemToObject(object, name, cJSON_CreateNumber(n))
#define cJSON_AddStringToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateString(s))
#define cJSON_AddRawToObject(object,name,s) cJSON_AddItemToObject(object, name, cJSON_CreateRaw(s))
/* When assigning an integer value, it needs to be propagated to valuedouble too. */
#define cJSON_SetIntValue(object,val) ((object) ? (object)->valueint = (object)->valuedouble = (val) : (val))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录