Linux安装JSON-C

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/

json标准 https://tools.ietf.org/html/rfc7159

★JASON-C的简介

JSON库多种多样,但是JSON-C由于兼容性好,支持UTF-8,所以使用比较广泛。

就json来说,由于结构比较简单,不用库也是可以的。

但json-c提供了超出json范围的一些功能,实际上完成了数据序列化和反序列化,数据的存储和检索,数据对象化等功能。还是非常有使用价值的。

https://github.com/json-c/json-c/wiki

官方API手册 : http://json-c.github.io/json-c/json-c-0.13.1/doc/html/index.html

http://zengriguang.blog.163.com/blog/static/17076248720121080187635/

 

1、下载安装JSON-C

有以下两种方式安装json-c

 1.1、使用yum工具安装

[root]# yum install json-c json-c-devel

  1.2、下载源码编译安装

//获取源代码
[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/wiki

Caution: 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`:

```make
CFLAGS += $(shell pkg-config --cflags json-c)
LDFLAGS += $(shell pkg-config --libs json-c)
```

Without `pkgconfig`, you would do something like this:

```make
JSON_C_DIR=/path/to/json_c/install
CFLAGS += -I$(JSON_C_DIR)/include/json-c
LDFLAGS+= -L$(JSON_C_DIR)/lib -ljson-c
```

 

 

 

posted @ 2014-06-26 23:27  LubinLew  阅读(20266)  评论(0编辑  收藏  举报