NameByNumber (Json function): Difference between revisions
(Automatically generated page update) |
No edit summary |
||
Line 1: | Line 1: | ||
{{Template:Json:NameByNumber subtitle}} | {{Template:Json:NameByNumber subtitle}} | ||
This function prints the name of a Jsob object item (property) based on the item number. | |||
This | |||
==Syntax== | ==Syntax== | ||
{{Template:Json:NameByNumber syntax}} | {{Template:Json:NameByNumber syntax}} | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%unicode</th><td> | <tr><th>%unicode</th><td>The name of the specified item number in the object.</td></tr> | ||
<tr><th>Json</th> | <tr><th>Json</th> | ||
<td>Json object</td></tr> | <td>Json object whose underlying object must be an object. If a null or other underlying type is used, an InvalidJsonType exception is thrown.</td></tr> | ||
<tr><th>number</th> | <tr><th>number</th> | ||
<td>number</td></tr> | <td>The item number whose name is to be returned.</td></tr> | ||
</table> | </table> | ||
==Usage notes== | ==Usage notes== | ||
<ul> | |||
<li>The item number must be between 1 and the number of items (inclusive) in the array or object ([[Count (Json property)|Count]]). An invalid item number results in request cancellation.</li> | |||
<li>For objects, the actual items can be retrieved by number using the [[ItemByNumber (Json function)|ItemByNumber function]].</li> | |||
</ul> | |||
==Examples== | ==Examples== | ||
The following example populates an object where each item is an array and then displays the name and value of each of the object items using NameByNumber and ItemByNumber: | |||
<p class="code">b | |||
%json is object json | |||
%i is float | |||
%json = object | |||
%json('Packers') = array(1967, 1968, 1997, 2011) | |||
%json('Steelers') = array(1975, 1976, 1979, 1980, 2006, 2009) | |||
%json('Cowboys') = array(1972, 1978, 1993, 1994, 1996, 2009) | |||
%json('49ers') = array(1982, 1985, 1989, 1990, 1995) | |||
%json('Patriots') = array(2002, 2004, 2005, 2015) | |||
for %i from 1 to %json:count | |||
printText {%json:nameByNumber(%i)}: {%json:itemByNumber(%i)} | |||
end for | |||
end | |||
</p> | |||
This prints: | |||
<p class="code">Packers: [1967,1968,1997,2011] | |||
Steelers: [1975,1976,1979,1980,2006,2009] | |||
Cowboys: [1972,1978,1993,1994,1996,2009] | |||
49ers: [1982,1985,1989,1990,1995] | |||
Patriots: [2002,2004,2005,2015] | |||
</p> | |||
==See also== | ==See also== | ||
{{Template:Json:NameByNumber footer}} | {{Template:Json:NameByNumber footer}} |
Revision as of 15:55, 18 February 2015
Get name of item in JSON object (Json class)
[Introduced in Model 204 7.6]
This function prints the name of a Jsob object item (property) based on the item number.
Syntax
%unicode = json:NameByNumber( number) Throws InvalidJsonType
Syntax terms
%unicode | The name of the specified item number in the object. |
---|---|
Json | Json object whose underlying object must be an object. If a null or other underlying type is used, an InvalidJsonType exception is thrown. |
number | The item number whose name is to be returned. |
Usage notes
- The item number must be between 1 and the number of items (inclusive) in the array or object (Count). An invalid item number results in request cancellation.
- For objects, the actual items can be retrieved by number using the ItemByNumber function.
Examples
The following example populates an object where each item is an array and then displays the name and value of each of the object items using NameByNumber and ItemByNumber:
b %json is object json %i is float %json = object %json('Packers') = array(1967, 1968, 1997, 2011) %json('Steelers') = array(1975, 1976, 1979, 1980, 2006, 2009) %json('Cowboys') = array(1972, 1978, 1993, 1994, 1996, 2009) %json('49ers') = array(1982, 1985, 1989, 1990, 1995) %json('Patriots') = array(2002, 2004, 2005, 2015) for %i from 1 to %json:count printText {%json:nameByNumber(%i)}: {%json:itemByNumber(%i)} end for end
This prints:
Packers: [1967,1968,1997,2011] Steelers: [1975,1976,1979,1980,2006,2009] Cowboys: [1972,1978,1993,1994,1996,2009] 49ers: [1982,1985,1989,1990,1995] Patriots: [2002,2004,2005,2015]