全部博文(2759)
分类:
2012-12-09 09:49:32
原文地址:JSON-C Example(从字符串解析属性) 作者:escarp
原文:
So you want to parse JSON with C? Welcome aboard! First get json-c, configure, compile, and update your ld cache
Make JSON-C (libjson)
x86 / Ubuntu
wget
tar xf json-c-0.9.tar.gz
cd json-c-0.9
./configure && make && sudo make install
sudo ldconfig
ARM / OpenEmbedded
bitbake json-c
Simple Test
Now use one of the test files provided or this example:
json-example.c:
Makefile:
all: static
# if you didn't do `sudo make install` you'll need to add your own paths
# to json.json.h and libjson.so - something like -I/usr/local/include/ -L/usr/local/lib
static:
gcc -static -o json-example-static json-example.c -ljson
./json-example-static
shared:
gcc -o json-example-shared json-example.c -L/usr/local/lib -ljson
./json-example-shared
.PHONY: all static shared
Make json-example
make static
make shared
Hopefully that's enough to get you started. The big thing is that when you compile your own projects, make sure that you include the json library and paths.
Segfaults
If you get a segfault it's most likely that you're accessing a key that doesn't exist.