Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Third Party CJSON
提交
4488c2b5
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,发现更多精彩内容 >>
提交
4488c2b5
编写于
5月 29, 2016
作者:
D
Dave Gamble
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #4 from irwand/fix_division_by_zero_test
Fix compiler div-by-0 error when it encountered 1.0/0.0
上级
87f55416
224c2a84
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
16 addition
and
15 deletion
+16
-15
test.c
test.c
+16
-15
未找到文件。
test.c
浏览文件 @
4488c2b5
/*
Copyright (c) 2009 Dave Gamble
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
...
...
@@ -28,7 +28,7 @@
void
doit
(
char
*
text
)
{
char
*
out
;
cJSON
*
json
;
json
=
cJSON_Parse
(
text
);
if
(
!
json
)
{
printf
(
"Error before: [%s]
\n
"
,
cJSON_GetErrorPtr
());}
else
...
...
@@ -44,7 +44,7 @@ void doit(char *text)
void
dofile
(
char
*
filename
)
{
FILE
*
f
;
long
len
;
char
*
data
;
f
=
fopen
(
filename
,
"rb"
);
fseek
(
f
,
0
,
SEEK_END
);
len
=
ftell
(
f
);
fseek
(
f
,
0
,
SEEK_SET
);
data
=
(
char
*
)
malloc
(
len
+
1
);
fread
(
data
,
1
,
len
,
f
);
data
[
len
]
=
'\0'
;
fclose
(
f
);
doit
(
data
);
...
...
@@ -68,11 +68,12 @@ void create_objects()
struct
record
fields
[
2
]
=
{
{
"zip"
,
37
.
7668
,
-
1.223959e+2
,
""
,
"SAN FRANCISCO"
,
"CA"
,
"94107"
,
"US"
},
{
"zip"
,
37
.
371991
,
-
1.22026e+2
,
""
,
"SUNNYVALE"
,
"CA"
,
"94085"
,
"US"
}};
volatile
double
zero
=
0
.
0
;
/* Here we construct some JSON standards, from the JSON site. */
/* Our "Video" datatype: */
root
=
cJSON_CreateObject
();
root
=
cJSON_CreateObject
();
cJSON_AddItemToObject
(
root
,
"name"
,
cJSON_CreateString
(
"Jack (
\"
Bee
\"
) Nimble"
));
cJSON_AddItemToObject
(
root
,
"format"
,
fmt
=
cJSON_CreateObject
());
cJSON_AddStringToObject
(
fmt
,
"type"
,
"rect"
);
...
...
@@ -80,7 +81,7 @@ void create_objects()
cJSON_AddNumberToObject
(
fmt
,
"height"
,
1080
);
cJSON_AddFalseToObject
(
fmt
,
"interlace"
);
cJSON_AddNumberToObject
(
fmt
,
"frame rate"
,
24
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
printf
(
"%s
\n
"
,
out
);
free
(
out
);
/* Print to text, Delete the cJSON, print it, release the string. */
/* Our "days of the week" array: */
...
...
@@ -93,7 +94,7 @@ void create_objects()
for
(
i
=
0
;
i
<
3
;
i
++
)
cJSON_AddItemToArray
(
root
,
cJSON_CreateIntArray
(
numbers
[
i
],
3
));
/* cJSON_ReplaceItemInArray(root,1,cJSON_CreateString("Replacement")); */
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
printf
(
"%s
\n
"
,
out
);
free
(
out
);
...
...
@@ -126,19 +127,19 @@ void create_objects()
cJSON_AddStringToObject
(
fld
,
"Zip"
,
fields
[
i
].
zip
);
cJSON_AddStringToObject
(
fld
,
"Country"
,
fields
[
i
].
country
);
}
/* cJSON_ReplaceItemInObject(cJSON_GetArrayItem(root,1),"City",cJSON_CreateIntArray(ids,4)); */
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
printf
(
"%s
\n
"
,
out
);
free
(
out
);
root
=
cJSON_CreateObject
();
cJSON_AddNumberToObject
(
root
,
"number"
,
1
.
0
/
0
.
0
);
cJSON_AddNumberToObject
(
root
,
"number"
,
1
.
0
/
zero
);
out
=
cJSON_Print
(
root
);
cJSON_Delete
(
root
);
printf
(
"%s
\n
"
,
out
);
free
(
out
);
}
int
main
(
int
argc
,
const
char
*
argv
[])
{
/* a bunch of json: */
char
text1
[]
=
"{
\n\"
name
\"
:
\"
Jack (
\\\"
Bee
\\\"
) Nimble
\"
,
\n\"
format
\"
: {
\"
type
\"
:
\"
rect
\"
,
\n\"
width
\"
: 1920,
\n\"
height
\"
: 1080,
\n\"
interlace
\"
: false,
\"
frame rate
\"
: 24
\n
}
\n
}"
;
char
text1
[]
=
"{
\n\"
name
\"
:
\"
Jack (
\\\"
Bee
\\\"
) Nimble
\"
,
\n\"
format
\"
: {
\"
type
\"
:
\"
rect
\"
,
\n\"
width
\"
: 1920,
\n\"
height
\"
: 1080,
\n\"
interlace
\"
: false,
\"
frame rate
\"
: 24
\n
}
\n
}"
;
char
text2
[]
=
"[
\"
Sunday
\"
,
\"
Monday
\"
,
\"
Tuesday
\"
,
\"
Wednesday
\"
,
\"
Thursday
\"
,
\"
Friday
\"
,
\"
Saturday
\"
]"
;
char
text3
[]
=
"[
\n
[0, -1, 0],
\n
[1, 0, 0],
\n
[0, 0, 1]
\n
]
\n
"
;
char
text4
[]
=
"{
\n
\"
Image
\"
: {
\n
\"
Width
\"
: 800,
\n
\"
Height
\"
: 600,
\n
\"
Title
\"
:
\"
View from 15th Floor
\"
,
\n
\"
Thumbnail
\"
: {
\n
\"
Url
\"
:
\"
http:/*www.example.com/image/481989943
\"
,
\n
\"
Height
\"
: 125,
\n
\"
Width
\"
:
\"
100
\"\n
},
\n
\"
IDs
\"
: [116, 943, 234, 38793]
\n
}
\n
}"
;
...
...
@@ -163,7 +164,7 @@ int main (int argc, const char * argv[]) {
/* Process each json textblock by parsing, then rebuilding: */
doit
(
text1
);
doit
(
text2
);
doit
(
text2
);
doit
(
text3
);
doit
(
text4
);
doit
(
text5
);
...
...
@@ -179,6 +180,6 @@ int main (int argc, const char * argv[]) {
/* Now some samplecode for building objects concisely: */
create_objects
();
return
0
;
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录