NumberValue (Json function)

From m204wiki
Revision as of 15:56, 23 August 2016 by ELowell (talk | contribs) (→‎Syntax terms)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Get number value of JSON object (Json class)

[Introduced in Model 204 7.6]

This function returns the number value of a Json object of the number type.

Syntax

%number = json:NumberValue Throws InvalidJsonType

Syntax terms

%numbernumber
Json Json object, which must have an underlying number type. If the Json object does not have the number type, an InvalidJsonType exception is thrown.

Usage notes

  • If the Json object has a string value that can be converted to a number, the Number method will still throw an InvalidJsonType exception. If a Json string value is known to be convertible to a number, extract it with the StringValue function and then assign it to a number (probably Float) variable.
  • The type of a Json object can be determined with the Type function.

Examples

The following example extracts the number values from items in an array and totals them:

b %json is object json %i is float %total is float %json = array(1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012) for %i from 1 to %json:count %total = %total + %json(%i):numberValue end for printText {~=%total} end

This prints:

%total=290512

See also