NameByNumber (Json function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
No edit summary
 
Line 5: Line 5:
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%unicode</th><td>The name of the specified item number in the object.</td></tr>
<tr><th nowrap>%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 whose underlying object must be an object. If a null or other underlying type is used, an InvalidJsonType exception is thrown.</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>
Line 11: Line 11:
<td>The item number whose name is to be returned.</td></tr>
<td>The item number whose name is to be returned.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>

Latest revision as of 15:54, 23 August 2016

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

%unicodeThe 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]

See also