Chinaunix首页 | 论坛 | 博客
  • 博客访问: 99521
  • 博文数量: 35
  • 博客积分: 637
  • 博客等级: 上士
  • 技术积分: 290
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-15 17:22
文章分类

全部博文(35)

文章存档

2015年(6)

2014年(1)

2013年(3)

2012年(25)

我的朋友

分类: C/C++

2015-07-23 17:04:36

#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");


  /*Creating a json integer*/
  json_object *jint = json_object_new_int(10);


  /*Creating a json boolean*/
  int a=1;
  json_object *jboolean = json_object_new_boolean(a);


  /*Creating a json double*/
  double d=100;
  json_object *jdouble = json_object_new_double(d);


  /*Creating a json array*/
  json_object *jarray = json_object_new_array();


  /*Creating json strings*/
  json_object *jstring1 = json_object_new_string("c");
  json_object *jstring2 = json_object_new_string("c++");
  json_object *jstring3 = json_object_new_string("php");


  /*Adding the above created json strings to the array*/
  json_object_array_add(jarray,jstring1);
  json_object_array_add(jarray,jstring2);
  json_object_array_add(jarray,jstring3);


  /*Form the json object*/
  /*Each of these is like a key value pair*/
  json_object_object_add(jobj,"Site Name", jstring);
  json_object_object_add(jobj,"Technical blog", jboolean);
  json_object_object_add(jobj,"Average posts per day", jdouble);
  json_object_object_add(jobj,"Number of posts", jint);
  json_object_object_add(jobj,"Categories", jarray);


  /*Now printing the json object*/
  const char *get_msg=json_object_to_json_string(jobj);
  printf ("The json object created: %sn",get_msg);


}

makefile:

json_object_get_type:json_object_get_type.o
gcc -o json_object_get_type json_object_get_type.o -ljson
clean:
rm -f json_object_get_type json_object_get_type.o



阅读(1522) | 评论(0) | 转发(0) |
0

上一篇:Ubuntu使用技巧合集

下一篇:没有了

给主人留下些什么吧!~~