NameByNumber (Json function)

From m204wiki
Revision as of 15:55, 18 February 2015 by Alex (talk | contribs)
Jump to navigation Jump to search

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