cJSON介紹及使用demo

2021-09-26 10:29:55 字數 1925 閱讀 9656

cjson

# demo1

}# demo2

, ,,,

,]

}

cjson是乙個超輕巧,攜帶方便,單檔案,簡單的可以作為ansi-c標準的json解析器。使用時,只需要包含cjson.h和cjson.c兩個檔案即可。

#include

"cjson.h"

#include

#include

/*建立乙個json物件

*/void

test01()

cjson_delete

(proot);}

/*建立乙個陣列

[1,2,3,4]

*/void

test02()

/*陣列的成員為物件

[ ,,,

]*/void

test03()

;char

* sznamearray=

;for

(int i =

0; i <

__crt_countof

(sznumarray)

; i++

)char

* szjson =

cjson_print

(proot);if

(!szjson)

return

;printf

("%s\n"

, szjson)

;free

(szjson)

;cjson_delete

(proot);}

/*,

, ,

]}*/

void

test04()

char

* sznumarray=

;char

* sznamearray=

;for

(int i =

0; i <

__crt_countof

(sznumarray)

; i++

)cjson_additemtoobject

(proot,

"student"

, psubroot)

;char

* szjson =

cjson_print

(proot);if

(!szjson)

return

;printf

("%s\n"

, szjson)

;free

(szjson)

;cjson_delete

(proot);}

/*解析json

*/cjson*

create()

char

* sznumarray=

;char

* sznamearray=

;for

(int i =

0; i <

__crt_countof

(sznumarray)

; i++

)cjson_additemtoobject

(proot,

"student"

, psubroot)

;char

* szjson =

cjson_print

(proot);if

(!szjson)

return

null

;printf

("%s\n"

, szjson)

;return proot;

}void

parse

(cjson* root)

}void

test05()

intmain()

PHP exec 函式的介紹和使用DEMO

exec 函式用來執行乙個外部程式,我們再用這函式基本是在linux。開啟exec 函式 exec 函式是被禁用的,要使用這個函式必須先開啟。首先是 要關掉 安全模式 safe mode off。然後在看看 禁用函式列表 disable functions proc open,popen,exec,...

cJSON 更新鍵值及物件

使用cjson過程中,有的時候只需要更新整個json物件中的部分資料,cjson中提供了這樣的介面,針對以下兩個介面,給出使用示例。cjson public void cjson replaceiteminarray cjson array,int which,cjson newitem cjson...

cJson使用方法

我使用的是cjson 先看json的資料結構 c中沒有物件,所以json資料是採用鍊錶儲存的typedef struct cjson cjson 比如你有乙個json資料 那麼你可以 1 講字串解析成json結構體。cjson root cjson parse my json string 2 獲取...