Linux安裝JSON-C

來源:互聯網
上載者:User

標籤: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```

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.