linux 下jansson安装和使用
1.安装jansson
./configure
Make
Make install
2.生成帮助文档
Cd doc
Make html
编译安装doc时提示 spinx-build not a command
执行下面语句安装sphinx
easy_install -U Sphinx
生成_build文件夹
Cd _build/html/
使用火狐浏览器启动帮助文档
Firefox index.html
3.编程
包含头文件: #include <jansson.h>
编译连接时加库 -ljansson:
gcc –o source source.c –ljansson
如果执行程序出现:error while loading shared libraries: libjansson.so.4: cannot open shared object file: No such file or directory
找不到libjansson.so.4这个库时用下面方法解决
//查找libjansson.so.4所在位置
Whereis libjansson
显示:libjansson: /usr/local/lib/libjansson.a /usr/local/lib/libjansson.la /usr/local/lib/libjansson.so
自己的libjansson.so所在位置为:/usr/local/lib/libjansson.so
//确定是否真的存在
cd /usr/local/lib
ls
//如果存在执行下面语句,创建一个libjansson.so的符号链接到/usr/lib目录下
ln -s /usr/local/lib/libjansson.so /usr/lib/libjansson.so.4
//重新加载库
Ldconfig
{"jsonStr":"{\"incID\":null,\"srcip\":null,\"desip\":null,\"protocol\":null,\"policyID\":null,\"snapshoot\":null,\"fileName\":null,\"fileType\":null,\"filePath\":null,\"domain\":null}","commandKey":"11100112"}
json_t *json_string(const char *value)
返回一个json string的数据类型,转换成这个库可以识别的格式。错误返回NULL,必须是UTF-8格式的。
Return value: New reference.
Returns a new JSON string, or NULL on error. value must be a valid UTF-8 encoded Unicode string.
json_t *json_string_nocheck(const char *value)
与json_string()相同,不检查value的有效性
Return value: New reference.
Like json_string(), but doesn’t check that value is valid UTF-8. Use this function only if you are certain that this really is the case (e.g. you have already checked it by other means).
const char *json_string_value(const json_t *string)
返回json string中的字符串,是c语言的字符串。
Returns the associated value of string as a null terminated UTF-8 encoded string, or NULL if string is not a JSON string.
The retuned value is read-only and must not be modified or freed by the user. It is valid as long as string exists, i.e. as long as its reference count has not dropped to zero.
int json_string_set(const json_t *string, const char *value)
设置string对应的值,如果value是无效的UTF-8值,设置失败。
Sets the associated value of string to value. value must be a valid UTF-8 encoded Unicode string. Returns 0 on success and -1 on error.
int json_string_set_nocheck(const json_t *string, const char *value)
与json_string_set()相同,只是不检查value是否是有效的UTF-8类型
Like json_string_set(), but doesn’t check that value is valid UTF-8. Use this function only if you are certain that this really is the case (e.g. you have already checked it by other means).
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。