StringValue (Json function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
(Automatically generated page update)
 
No edit summary
Line 1: Line 1:
{{Template:Json:StringValue subtitle}}
{{Template:Json:StringValue subtitle}}
 
This function returns the number value of a Json object of the string type.
This page is [[under construction]].
==Syntax==
==Syntax==
{{Template:Json:StringValue syntax}}
{{Template:Json:StringValue syntax}}
===Syntax terms===
===Syntax terms===
<table class="syntaxTable">
<table class="syntaxTable">
<tr><th>%unicode</th><td>Unicode</td></tr>
<tr><th>%unicode</th><td>The value of the json string data which, as the name suggests, is always unicode though if the target is EBCDIC, the unicode is converted automatically into EBCDIC.</td></tr>
<tr><th>Json</th>
<tr><th>Json</th>
<td>Json object, which may be <var>Null</var></td></tr>
<td>Json object, which must have an underlying string type. If the Json object is doesn't have the string type, an InvalidJsonType exception is thrown.</td></tr>
</table>
</table>
==Usage notes==
==Usage notes==
<ul>
<li>If the Json object has a number value, while that numebr can always be converted to a string, the String method will still throw an InvalidJsonType exception. If one wishes to extract a Json string from a number object, extract it with the [[NumberValue (Json function)|NumberValue]] function and then assign it to a string (String, Longstring, or Unicode) variable.</li>
<li>The type of a Json object can be determined with the [[Type (Json function)|Type function]].</li>
<li>While the result of StringValue will be automatically converted to EBCDIC as needed, if the source might contain untranslatable unicode characters, this automatic assignment could result in a request canceling error. If this is a potential issue, use unicode variables to hold all the data or apply the [[UnicodeToEbcdic (Unicode function)|UnicodeToEbcdic function]] to the StringValue result and catch the possible [[CharacterTranslationException class|CharacterTranslationException]].
</ul>
==Examples==
==Examples==
The following example finds the lexicographically smallest value in an array and prints it:
<p class="code">b
%json        is object json
%i          is float
%min        is string len 32
%json = array("United States", "Canada", "Mexico", "Belize", "Nicaragua")
%min = %json(1):stringValue
for %i from 2 to %json:count
  if %min gt %json(%i):stringValue then
      %min = %json(%i):stringValue
  end if
end for
printText {~=%min}
end
</p>
This prints:
<p class="code">%min=Belize
</p>
==See also==
==See also==
{{Template:Json:StringValue footer}}
{{Template:Json:StringValue footer}}

Revision as of 22:12, 18 February 2015

Get string value of JSON object (Json class)

[Introduced in Model 204 7.6]

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

Syntax

%unicode = json:StringValue Throws InvalidJsonType

Syntax terms

%unicodeThe value of the json string data which, as the name suggests, is always unicode though if the target is EBCDIC, the unicode is converted automatically into EBCDIC.
Json Json object, which must have an underlying string type. If the Json object is doesn't have the string type, an InvalidJsonType exception is thrown.

Usage notes

  • If the Json object has a number value, while that numebr can always be converted to a string, the String method will still throw an InvalidJsonType exception. If one wishes to extract a Json string from a number object, extract it with the NumberValue function and then assign it to a string (String, Longstring, or Unicode) variable.
  • The type of a Json object can be determined with the Type function.
  • While the result of StringValue will be automatically converted to EBCDIC as needed, if the source might contain untranslatable unicode characters, this automatic assignment could result in a request canceling error. If this is a potential issue, use unicode variables to hold all the data or apply the UnicodeToEbcdic function to the StringValue result and catch the possible CharacterTranslationException.

Examples

The following example finds the lexicographically smallest value in an array and prints it:

b %json is object json %i is float %min is string len 32 %json = array("United States", "Canada", "Mexico", "Belize", "Nicaragua") %min = %json(1):stringValue for %i from 2 to %json:count if %min gt %json(%i):stringValue then %min = %json(%i):stringValue end if end for printText {~=%min} end

This prints:

%min=Belize

See also