Add (Json function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{Template:Json:Add subtitle}}
{{Template:Json:Add subtitle}}


This page is [[under construction]].
This functions adds a Json object to a Json array.
==Syntax==
==Syntax==
{{Template:Json:Add syntax}}
{{Template:Json:Add syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%number</th><td>number</td></tr>
<tr><th>%number</th><td>The number of items in the array after the Add.</td></tr>
<tr><th>Json</th>
<tr><th>Json</th>
<td>Json object, which may be <var>Null</var></td></tr>
<td>Json object, which must be an array or an InvalidJsonType exception is thrown.</td></tr>
<tr><th>json</th>
<tr><th>json</th>
<td><var>Json</var> object</td></tr>
<td><var>Json</var> object that can be <var>Null</var>.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>The added Json object becomes the last item in the array.</li>
<li>The value returned by Add is the same value that would be returned by an immediately following [[Count (Json property)|Count function]].</li>
<li>Unlike the [[Add (Arraylist function)|Arraylist]] and [[Add (Stringlist function)|Stringlist]] Add methods, only one item can be added with the Json Add function.</li>
</ul>
==Examples==
==Examples==
The following request adds the string "Start", the first 10 prime numbers, and then the string "End" to a Json object that is an array. This illustrates how different Json object types can be added to the same array. In fact, it would also possible to add a Boolean, Object, or even another Array type to the array.
<p class="code">b
%i      float
%json    is object json
%prime  is float
%json = array
%json:add("Start")
for %i from 1 to 10
  %prime = %prime:nextPrime
  %json:add(%prime)
end for
%json:add("End")
printtext {~=%json}
end
</p>
This program prints:
<p class="code">%json=["Start",2,3,5,7,11,13,17,19,23,29,"End"]
</p>
==See also==
==See also==
{{Template:Json:Add footer}}
{{Template:Json:Add footer}}

Latest revision as of 21:11, 17 February 2015

Add an item to a JSON array (Json class)

[Introduced in Model 204 7.6]


This functions adds a Json object to a Json array.

Syntax

[%number =] json:Add( json) Throws InvalidJsonType

Syntax terms

%numberThe number of items in the array after the Add.
Json Json object, which must be an array or an InvalidJsonType exception is thrown.
json Json object that can be Null.

Usage notes

  • The added Json object becomes the last item in the array.
  • The value returned by Add is the same value that would be returned by an immediately following Count function.
  • Unlike the Arraylist and Stringlist Add methods, only one item can be added with the Json Add function.

Examples

The following request adds the string "Start", the first 10 prime numbers, and then the string "End" to a Json object that is an array. This illustrates how different Json object types can be added to the same array. In fact, it would also possible to add a Boolean, Object, or even another Array type to the array.

b %i float %json is object json %prime is float %json = array %json:add("Start") for %i from 1 to 10 %prime = %prime:nextPrime %json:add(%prime) end for %json:add("End") printtext {~=%json} end

This program prints:

%json=["Start",2,3,5,7,11,13,17,19,23,29,"End"]

See also