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/

★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/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
```
复制代码


FROM:http://www.cnblogs.com/LubinLew/p/Linux_JSON-C_Install.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值