標籤:style blog http java color get
0、JSON簡介
JSON(JavaScript Object Notation) 是一種輕量級的資料交換格式。易於人閱讀和編寫。同時也易於機器解析和產生。
JSON採用完全獨立於語言的文字格式設定,但是也使用了類似於C語言家族的習慣(包括C, C++, C#, Java, JavaScript, Perl, Python等)。這些特性使JSON成為理想的資料交換語言。
跟XML相比,JSON的優勢在于格式簡潔短小,特別是在處理大量複雜資料的時候,這個優勢便顯得非常突出。從各瀏覽器的支援來看,JSON解決了因不同瀏覽器對XML DOM解析方式不同而引起的問題。
★JASON的學習資料
http://www.json.org/ (英文) http://www.json.org/json-zh.html (中文)
http://www.w3school.com.cn/json/
http://www.ibm.com/developerworks/cn/web/wa-lo-json/
★JASON-C的簡介
JSON庫多種多樣,但是JSON-C由於相容性好,支援UTF-8,所以使用比較廣泛。
就json來說,由於結構比較簡單,不用庫也是可以的。
但json-c提供了超出json範圍的一些功能,實際上完成了資料序列化和還原序列化,資料的儲存和檢索,資料對象化等功能。還是非常有使用價值的。
https://github.com/json-c/json-c/wiki
http://zengriguang.blog.163.com/blog/static/17076248720121080187635/
1、編譯JSON-C
//擷取原始碼[root]# yum install git[root]# git clone https://github.com/json-c/json-c.git//編譯安裝[root]# cd json-c[root]# ./autogen.sh[root]# ./configure[root]# make[root]# make install
2、使用JSON-C
如果你的Linux中沒有pkgconfig
//安裝pkgconfig[root]# yum install pkgconfig
編譯使用JSON-C標頭檔,連結JSON-C庫時需要在makefile中增加如下依賴關係
CFLAGS += $(shell pkg-config --cflags json-c)LDFLAGS += $(shell pkg-config --libs json-c)
//或者簡單一點
gcc `pkg-config --cflags --libs json-c` -o target xxx.c
3、
例子
4、JSON-C的README.md檔案
`json-c`========Building on Unix with `git`, `gcc` and `autotools`--------------------------------------------------Home page for json-c: https://github.com/json-c/json-c/wikiCaution: do **NOT** use sources from svn.metaparadigm.com,they are old.Prerequisites: - `gcc`, `clang`, or another C compiler - `libtool`If you‘re not using a release tarball, you‘ll also need: - `autoconf` (`autoreconf`) - `automake`Make sure you have a complete `libtool` install, including `libtoolize`.`json-c` GitHub repo: https://github.com/json-c/json-c```bash$ git clone https://github.com/json-c/json-c.git$ cd json-c$ sh autogen.sh```followed by```bash$ ./configure$ make$ make install```To build and run the test programs:```bash$ make check```Linking to `libjson-c`----------------------If your system has `pkgconfig`,then you can just add this to your `makefile`:```makeCFLAGS += $(shell pkg-config --cflags json-c)LDFLAGS += $(shell pkg-config --libs json-c)```Without `pkgconfig`, you would do something like this:```makeJSON_C_DIR=/path/to/json_c/installCFLAGS += -I$(JSON_C_DIR)/include/json-cLDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c```