Object (Json function): Difference between revisions
(Automatically generated page update) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Template:Json:Object subtitle}} | {{Template:Json:Object subtitle}} | ||
This function creates a Json object with an underlying type of object. | |||
==Summary== | |||
A Json object is a collection of pairs of (unicode) names and Json objects (null, number, string, boolean, array, or object). In serialized JSON, an object is represented as curly braces containing pairs of quoted names followed by colon followed by the value. The pairs are separated from each other with commas. | |||
The following is a sample Json serialization of an object: | |||
<p class="code">{"Name":"sprocket","Cost":23.18,"Source":null,"Sizes":["Small","Medium","Large"]} | |||
</p> | |||
==Syntax== | ==Syntax== | ||
{{Template:Json:Object syntax}} | {{Template:Json:Object syntax}} | ||
Line 8: | Line 13: | ||
<tr><th>%json</th><td><var>Json</var> object</td></tr> | <tr><th>%json</th><td><var>Json</var> object</td></tr> | ||
<tr><th nowrap="true"><var>[%(Json):]</var></th> | <tr><th nowrap="true"><var>[%(Json):]</var></th> | ||
<td>The optional class name in parentheses denotes a [[Notation conventions for methods#Constructors|virtual constructor]] | <td>The optional class name in parentheses denotes a [[Notation conventions for methods#Constructors|virtual constructor]].</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>As with all virtual or true constructors, it is usually not necessary to specify the <code>%(json):</code> before the Object method. That is <code>%json = %(json):object</code> is equivalent to <code>%json = object</code>.</li> | |||
<li>Unlike [[Array (Json function)|Json arrays]] it is not possible to specify names and values on the Object virtual constructor. Instead, the must be added to the object with the [[Add (Json function)|Add]] or [[Item (Json property)|Item]] methods.</li> | |||
</ul> | |||
==Examples== | ==Examples== | ||
The following example populates an object with the values shown above: | |||
<p class="code">b | |||
%json is object json | |||
%i is float | |||
%total is float | |||
%json = object | |||
%json('Name') = 'sprocket' | |||
%json('Cost') = 23.18 | |||
%json('Source') = null | |||
%json('Sizes') = array("Small", "Medium", "Large") | |||
printText {~=%json} | |||
end | |||
</p> | |||
This prints: | |||
<p class="code">%json={"Name":"sprocket","Cost":23.18,"Source":null,"Sizes":["Small","Medium","Large"]} | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:Json:Object footer}} | {{Template:Json:Object footer}} |
Latest revision as of 19:34, 18 February 2015
Create an Object JSON object (Json class)
[Introduced in Model 204 7.6]
This function creates a Json object with an underlying type of object.
Summary
A Json object is a collection of pairs of (unicode) names and Json objects (null, number, string, boolean, array, or object). In serialized JSON, an object is represented as curly braces containing pairs of quoted names followed by colon followed by the value. The pairs are separated from each other with commas.
The following is a sample Json serialization of an object:
{"Name":"sprocket","Cost":23.18,"Source":null,"Sizes":["Small","Medium","Large"]}
Syntax
%json = [%(Json):]Object
Syntax terms
%json | Json object |
---|---|
[%(Json):] | The optional class name in parentheses denotes a virtual constructor. |
Usage notes
- As with all virtual or true constructors, it is usually not necessary to specify the
%(json):
before the Object method. That is%json = %(json):object
is equivalent to%json = object
. - Unlike Json arrays it is not possible to specify names and values on the Object virtual constructor. Instead, the must be added to the object with the Add or Item methods.
Examples
The following example populates an object with the values shown above:
b %json is object json %i is float %total is float %json = object %json('Name') = 'sprocket' %json('Cost') = 23.18 %json('Source') = null %json('Sizes') = array("Small", "Medium", "Large") printText {~=%json} end
This prints:
%json={"Name":"sprocket","Cost":23.18,"Source":null,"Sizes":["Small","Medium","Large"]}