NumberByName (Json function): Difference between revisions
(Automatically generated page update) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Template:Json:NumberByName subtitle}} | {{Template:Json:NumberByName subtitle}} | ||
This function returns the item number associated with a particular name in a Json object with an underlying object type. | |||
This | |||
==Syntax== | ==Syntax== | ||
{{Template:Json:NumberByName syntax}} | {{Template:Json:NumberByName 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 the item with the specified name. If no item has the name, a 0 is returned.</td></tr> | ||
<tr><th>Json</th> | <tr><th>Json</th> | ||
<td>Json object</td></tr> | <td>Json object which must have an underlying type of object. A null or any other underlying type throws an InvalidjsonType exception.</td></tr> | ||
<tr><th>unicode</th> | <tr><th>unicode</th> | ||
<td> | <td>The name to be found. As <i>unicode</i> suggests, this name is treated as unicode since all names are stored internally as unicode.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>Probably the main use of NumberByName is to determine if a given name is present in an object. Since the [[Item (Json property)|Item property]] will return a null if either the requested name is not present in the object or if the value associated with that name is null, NumberByName is one way to distinguish those cases.</li> | |||
</ul> | |||
==Examples== | ==Examples== | ||
The following example populates an object with some values and then retrieves the values for names "Ostrich" and "Diplodocus". As you can see, the values are identical. However, the NumberByName method values for "Ostrich" and "Diplodocus" reveal the one is in the object but set to null while the other is simply not in the object. | |||
<p class="code">b | |||
%json is object json | |||
%json = object | |||
%json("Tiger") = "Asia" | |||
%json("Lion") = "Africa" | |||
%json("Diplodocus") = null | |||
%json("Elk") = array("North America", "Asia") | |||
%json("Kangaroo") = "Australia" | |||
printText {~=%json("Ostrich")} | |||
printText {~=%json("Diplodocus")} | |||
printText {~=%json:numberByName("Ostrich")} | |||
printText {~=%json:numberByName("Diplodocus")} | |||
end | |||
</p> | |||
This prints: | |||
<p class="code">%json("Ostrich")=null | |||
%json("Diplodocus")=null | |||
%json:numberByName("Ostrich")=0 | |||
%json:numberByName("Diplodocus")=3 | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:Json:NumberByName footer}} | {{Template:Json:NumberByName footer}} |
Revision as of 19:06, 18 February 2015
Get number of named item in JSON object (Json class)
[Introduced in Model 204 7.6]
This function returns the item number associated with a particular name in a Json object with an underlying object type.
Syntax
%number = json:NumberByName( unicode)
Syntax terms
%number | The number of the item with the specified name. If no item has the name, a 0 is returned. |
---|---|
Json | Json object which must have an underlying type of object. A null or any other underlying type throws an InvalidjsonType exception. |
unicode | The name to be found. As unicode suggests, this name is treated as unicode since all names are stored internally as unicode. |
Usage notes
- Probably the main use of NumberByName is to determine if a given name is present in an object. Since the Item property will return a null if either the requested name is not present in the object or if the value associated with that name is null, NumberByName is one way to distinguish those cases.
Examples
The following example populates an object with some values and then retrieves the values for names "Ostrich" and "Diplodocus". As you can see, the values are identical. However, the NumberByName method values for "Ostrich" and "Diplodocus" reveal the one is in the object but set to null while the other is simply not in the object.
b %json is object json %json = object %json("Tiger") = "Asia" %json("Lion") = "Africa" %json("Diplodocus") = null %json("Elk") = array("North America", "Asia") %json("Kangaroo") = "Australia" printText {~=%json("Ostrich")} printText {~=%json("Diplodocus")} printText {~=%json:numberByName("Ostrich")} printText {~=%json:numberByName("Diplodocus")} end
This prints:
%json("Ostrich")=null %json("Diplodocus")=null %json:numberByName("Ostrich")=0 %json:numberByName("Diplodocus")=3