標籤:des code c int strong com
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瀏覽器啟動協助文檔
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).