json_object_new_double- Create a new double json object
Posted by Joys of Programming on in json-c
json_object_new_double is used to create a new double json object.
The syntax of the function is
json_object * json_object_new_double (char *s)
Specify the double 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 double*/
json_object *jdouble = json_object_new_double(3.14);
/*Form the json object*/
json_object_object_add(jobj,"PI", jdouble);
/*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: { "PI": 3.140000 }
Comments: