json_object_new_string- Create a new string json object

Posted by Joys of Programming on in json-c

json_object_new_string is used to create a new string json object.

The syntax of the function is

json_object * json_object_new_string (char *s)

Specify the string as the argument and it returns a pointer to the json object

The following program shows the usage of the function


#include <json/json.h>
#include <stdio.h>

int main() {
  /*Creating a json object*/
  json_object * jobj = json_object_new_object();

  /*Creating a json string*/
  json_object *jstring = json_object_new_string("Joys of Programming");

  /*Form the json object*/
  json_object_object_add(jobj,"Site Name", jstring);

  /*Now printing the json object*/
  printf ("The json object created: %s\n",json_object_to_json_string(jobj));

}


The output of the program is something like this

The json object created: { "Site Name": "Joys of Programming" }


Tags: , , , , ,

Comments:

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Copyright © 2009-2012 Joys of Programming All rights reserved.
Desk Mess Mirrored v1.8.1 theme from BuyNowShop.com.