linux 下jansson安裝和使用

來源:互聯網
上載者:User

標籤: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 valuevalue 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).

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.