日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

cJsonFiles数据结构

發(fā)布時(shí)間:2025/4/14 编程问答 18 豆豆
生活随笔 收集整理的這篇文章主要介紹了 cJsonFiles数据结构 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
先看json的數(shù)據(jù)結(jié)構(gòu)

c中沒(méi)有對(duì)象,所以json數(shù)據(jù)是采用鏈表存儲(chǔ)的

view sourceprint? 01.typedef struct cJSON { 02.struct cJSON *next,*prev;????// 數(shù)組 對(duì)象數(shù)據(jù)中用到 03.struct cJSON *child;????????// 數(shù)組 和對(duì)象中指向子數(shù)組對(duì)象或值 04.?? 05.int type;????????????// 元素的類型,如是對(duì)象還是數(shù)組 06.?? 07.char *valuestring;????????????// 如果是字符串 08.int valueint;????????????????// 如果是數(shù)值 09.double?valuedouble;????????????// 如果類型是cJSON_Number 10.?? 11.char *string;????????????????// The item's name string, if this item is the child of, or is in the list of subitems of an object. 12.} cJSON;

比如你有一個(gè)json數(shù)據(jù)

view sourceprint? 01.{ 02."name":?"Jack (\"Bee\") Nimble", 03."format": { 04."type":???????"rect", 05."width":??????1920, 06."height":?????1080, 07."interlace":??false, 08."frame rate":?24 09.} 10.}

那么你可以

1:講字符串解析成json結(jié)構(gòu)體。

cJSON?*root?=?cJSON_Parse(my_json_string);
2:獲取某個(gè)元素

cJSON?*format?=?cJSON_GetObjectItem(root,”format”);

int?framerate?=?cJSON_GetObjectItem(format,”frame?rate”)->valueint;

3:講json結(jié)構(gòu)體轉(zhuǎn)換成字符串

char?*rendered=cJSON_Print(root);

4:刪除

cJSON_Delete(root);

5:構(gòu)建一個(gè)json結(jié)構(gòu)體

view sourceprint? 01.cJSON *root,*fmt; 02.root=cJSON_CreateObject(); 03.cJSON_AddItemToObject(root,?"name", cJSON_CreateString("Jack (\"Bee\") Nimble")); 04.cJSON_AddItemToObject(root,?"format", fmt=cJSON_CreateObject()); 05.cJSON_AddStringToObject(fmt,"type",????????"rect"); 06.cJSON_AddNumberToObject(fmt,"width",????????1920); 07.cJSON_AddNumberToObject(fmt,"height",????????1080); 08.cJSON_AddFalseToObject (fmt,"interlace"); 09.cJSON_AddNumberToObject(fmt,"frame rate",????24);

?


總結(jié)

以上是生活随笔為你收集整理的cJsonFiles数据结构的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。