首页 > 代码库 > mjson学习的简单例子分享
mjson学习的简单例子分享
01
#include <mjson/json.h>
02
#include <stdio.h>
03
#include <stdlib.h>
04
int main()
05
{
06
json_t *entry, *root, *head, *body, *label, *value;
07
char *document;
08
root = json_new_object();
09
10
/*--------Head------*/
11
12
head = json_new_string("head");
13
entry = json_new_object();
14
15
label = json_new_string("ID");
16
value = http://www.mamicode.com/json_new_number("1");
17
json_insert_child(label,value);
18
json_insert_child(entry,label);
19
20
label = json_new_string("Tyep");
21
value = http://www.mamicode.com/json_new_string("0");
22
json_insert_child(label,value);
23
json_insert_child(entry,label);
24
25
26
json_insert_child(head, entry);
27
/*------End Head------*/
28
29
/*---------Body---------*/
30
body = json_new_string("body");
31
entry = json_new_object();
32
33
label = json_new_string("phone");
34
value = http://www.mamicode.com/json_new_string("028-2306987");
35
json_insert_child(label,value);
36
json_insert_child(entry, label);
37
38
label = json_new_string("address");
39
value = http://www.mamicode.com/json_new_string("Los Angeles");
40
json_insert_child(label,value);
41
json_insert_child(entry,label);
42
43
label = json_new_string("name");
44
json_t *array = json_new_array();
45
value = http://www.mamicode.com/json_new_string("Jack");
46
json_insert_child(array,value);
47
value = http://www.mamicode.com/json_new_string("Mike");
48
json_insert_child(array,value);
49
value = http://www.mamicode.com/json_new_string("Kobe");
50
json_insert_child(array,value);
51
json_insert_child(label,array);
52
json_insert_child(entry,label);
53
54
json_insert_child(body,entry);
55
/*------End Body-------*/
56
57
json_insert_child(root,head);
58
json_insert_child(root,body);
59
60
json_tree_to_string(root,&document);
61
printf("%s\n", document);
62
json_free_value(&root);
63
64
65
/*---Parsing the documents---*/
66
json_parse_document(&root,document);
67
68
head = json_find_first_label(root,"head");
69
body = json_find_first_label(root,"body");
70
71
label = json_find_first_label(head->child,"ID");
72
printf("%s\n",label->child->text);
73
74
75
/*clean up*/
76
free(document);
77
json_free_value(&root);
78
exit(0);
jquery tab标签
文章来源:http://www.huiyi8.com/tab/query/