Compile the Json-c library under VS2013 and simply generate JSON-formatted data

Source: Internet
Author: User

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

int _tmain (int argc, _tchar* argv[])
{
Normal JSON format
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));
Produces a JSON array format
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);
The data contains the normal JSON format
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);
Output
const char *STR = json_object_to_json_string (JSON);
/*
{"Name": "Laomeng", "email": "[email protected]", "age": +, "technology": ["C", "C + +", "PHP"], "technology2": [{"Nam E ":" Laomeng "," email ":" [email protected] "," Age ": 30}]}
*/

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

Json_object_put (JSON);
return 0;
}

Compile the Json-c library under VS2013 and simply generate JSON-formatted data

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.