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 = 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 = 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 = 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 = 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 = json_new_string("Jack");
46
json_insert_child(array,value);
47
value = json_new_string("Mike");
48
json_insert_child(array,value);
49
value = 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/
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。