This repository was archived by the owner on Apr 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdevelopment_javascript_JSON.html
More file actions
147 lines (112 loc) · 3.84 KB
/
development_javascript_JSON.html
File metadata and controls
147 lines (112 loc) · 3.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Mobile Widgets</title>
<link rel="stylesheet" href="style/style.css" />
<link rel="shortcut icon" href="images/favicon.ico" type="image/x-icon" />
<script type="text/javascript" src="js/StructureElts.js"></script>
<script type="text/javascript" src="js/Structure.js"></script>
<script type="text/javascript" src="js/DocElements.js"></script>
</head>
<body>
<script type="text/javascript">
<!--
idCurrentPage = "development_javascript_JSON";
beginPage();
//-->
</script>
<h1 class="title">JSON Javascript library</h1>
<script type="text/javascript">
<!--
addIndex();
//-->
</script>
<p class="note warning">
<b>Warning:</b><br/>
This tutorial covers only Mobile Widgets versions.<br/>
Tiny Widgets don't support JSON</a>.
</p>
<script type="text/javascript">addTitle("Description", 1);</script>
<p>
Load and parse JSON data.
</p>
<script type="text/javascript">addTitle("Methods", 1);</script>
<p>
<b>int open (String buffer, int mode)</b>:<br/>
Create a JSON DOM by parsing the provided buffer or url according to mode.<br/>
The value returned must be used for all subsequent operations on this DOM.
</p>
<p>
<b>void close (int id)</b>:<br/>
Destroy the DOM and release any resources associated to <b>id</b>.
</p>
<p>
<b>bool find (int id, String path)</b>:<br/>
Set a pointer to an element defined by the path.<br/>
The form of this path is nodeName1/nodeName2/...<br/>
If the value of the node is an array and not an Object, then the form <b>index</b>
can be used instead.<br/>
Example: main/table*1/key points to the key element that is stored at the second
position inside the array associated to table, child of main, like in:
</p>
<textarea wrap="off" readonly="readonly" rows="1" cols="80">
{"main" : { "table" : [ { "id" : 1234}, {"key" : 2} ] }, "list" : [ 1, 2] }}
</textarea>
<p>
This obviously implies that the structure is known in advance!
</p>
<p>
<b>int/String getValue (int id)</b>:<br/>
Returns the value located to the previous find command.<br/>
This will return 0 for types other that string, number and constants (true, false and null).<br/>
In the previous example, returns the number 2.
</p>
<p>
<b>int getType (int id)</b>:<br/>
Returns the type of the value located to the previous find command.<br/>
In the previous example, returns <b>JSON.NUMBER</b>.
</p>
<p>
<b>int getSize (int id)</b>:<br/>
Returns the size of the value located to the previous find command.<br/>
Returns always 1 except for arrays.
</p>
<br/>
<script type="text/javascript">addTitle("Constants", 1);</script>
<p>
<b>NUMBER, STRING, OBJECT, ARRAY, TRUE, FALSE, NULL, ERROR</b>:<br/>
Types returned by the <b>JSON.getType ()</b> method.
</p>
<p>
<b>BUFFER, URL, KEEP_ALIVE, DEBUG, ASYNC</b>:<br/>
Values that can be used for the <b>mode</b> argument of the <b>JSON.open()</b> method.
</p>
<br/>
<script type="text/javascript">addTitle("Examples", 1);</script>
<textarea wrap="off" readonly="readonly" rows="10" cols="80">
function parseJson(){
// Quotes are not interpreted in the script thanks to the slashes
var jsondata = '{\"result\":\"myContent\",\"id\":1}'; // The corresponding Json string is: {"result":"myContent","id":1}
// Parse Json response, like the Xml parser
var id = JSON.open(jsondata , JSON.BUFFER);
JSON.find(id, '/result');
Browser.print('Result: '+JSON.getValue(id)); // Prints "Result: myContent"
JSON.close(id); // Free all resources associated to the DOM
}
</textarea>
<br/>
<script type="text/javascript">
<!--
addBackPageNavigator('widgets_development_javascript_ref', '');
//-->
</script>
<script type="text/javascript">
<!--
endPage();
//-->
</script>
</body>
</html>