在VS2013下編譯json-c庫,並簡單產生json格式資料

來源:互聯網
上載者:User

標籤:argc   har   編譯   char   簡單   object   []   php   ons   

#include "stdafx.h"
#include "json-c/json.h"

int _tmain(int argc, _TCHAR* argv[])
{
// 正常的json格式
json_object *json = json_object_new_object();
json_object_object_add(json, "name", json_object_new_string("laomeng"));
json_object_object_add(json, "email", json_object_new_string("[email protected]"));
json_object_object_add(json, "age", json_object_new_int(30));
// 產生一個json數組格式
json_object *tech = json_object_new_array();
json_object_array_add(tech, json_object_new_string("c"));
json_object_array_add(tech, json_object_new_string("c++"));
json_object_array_add(tech, json_object_new_string("php"));
json_object_object_add(json, "technology", tech);
// 資料中包含正常json格式
json_object *tech2 = json_object_new_array();
json_object *json_sub = json_object_new_object();
json_object_object_add(json_sub, "name", json_object_new_string("laomeng"));
json_object_object_add(json_sub, "email", json_object_new_string("[email protected]"));
json_object_object_add(json_sub, "age", json_object_new_int(30));
json_object_array_add(tech2, json_sub);
json_object_object_add(json, "technology2", tech2);
// 輸出
const char *str = json_object_to_json_string(json);
/*
{ "name": "laomeng", "email": "[email protected]", "age": 30, "technology": [ "c", "c++", "php" ], "technology2": [ { "name": "laomeng", "email": "[email protected]", "age": 30 } ] }
*/

printf("%s\n", str);

json_object_put(json);
return 0;
}

在VS2013下編譯json-c庫,並簡單產生json格式資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.