cJSON 官方測試程式詳解

2021-09-24 04:03:54 字數 3977 閱讀 2853

這是cjson官方提供的乙個測試小demo, 比較好讀。主要的作用是將記憶體中的資料,轉化為json格式資料,以及將json格式的資料轉為字串輸出到螢幕或檔案中

#include #include #include "cjson.h"

/* parse text to json, then render back to text, and print! */

/* 將字串轉為json格式,在將json格式檔案轉為字串輸出 */

void doit(char *text)

// 轉換失敗輸出錯誤提示

else }

/* read a file, parse, render back, etc. */

/* 從乙個檔案讀取字串,轉成json格式,在轉為字串輸出到螢幕上*/

void dofile(char *filename)

/* used by some code below as an example datatype. */

/* 這個結構體是例子統一中一種常見的結構 */

struct record ;

/* create a bunch of objects as demonstration. */

void create_objects()

; /* our matrix: 矩陣陣列 */

int numbers[3][3]=,,};

/* our "gallery" item: 陣列*/

int ids[4]=;

/* our array of "records": 記錄結構體*/

struct record fields[2]=,

};/* here we construct some json standards, from the json site. */

/* our "video" datatype: */

root=cjson_createobject(); // 建立乙個cjson物件

cjson_additemtoobject(root, "name", cjson_createstring("jack (\"bee\") nimble")); // 新增乙個資料

C json亂碼轉中文 已測試

使用api得到的資料報括中文,得到的中文是unicode編碼,即看到的是亂碼,將其轉為正常的中文使用以下第三條,其餘的是相反情況。1.中文轉unicode public static string unicode 0 string str return outstr 2.unicode轉中文 pub...

Windows XP SP3細節官方詳解

windows xp sp3預計本週即將正式發布。上周末,微軟在官方 上放出了名為 overview of windows xp service pack 3 的細節預覽 對xp sp3的內容和其他細節進行了解釋。微軟著重強調稱,xp sp3包括了windows xp的全部公升級補丁,也包含少量新功...

mysql官方基準測試結果 mysql 基準測試

mysql 基準測試 基準測試策略 整合式 將整個應用包括mysql作為整體 單元件式 單獨測試mysql系統 基準測試指標 吞吐量 響應時間 擴充套件性 併發性 基準測試工具 整合測試工具 ab http load jmeter 但元件測試工具 mysqlslap sysbench databas...