JSON.Parse: Difference between revisions

From NSB App Studio
Jump to navigation Jump to search
Brendon (talk | contribs)
Created page with "JSON.PARSE (''string''[, ''reviver'']) '''Description''' JSON.PARSE converts a string created by JSON.STRINGIFY into an NS Basic object. It is useful for interchanging data ..."
 
Brendon (talk | contribs)
No edit summary
Line 1: Line 1:
JSON.PARSE (''string''[, ''reviver''])
Json.Parse (''string''[, ''reviver''])


'''Description'''
== Description ==


JSON.PARSE converts a string created by JSON.STRINGIFY into an NS Basic object. It is useful for interchanging data with other systems and for saving objects to localStorage and databases. ''string'' is the string to be converted. ''reviver'' is an optional function name that can be used to do some processing of the data while being parsed.
Json.Parse converts a string created by JSON.STRINGIFY into an NS Basic object. It is useful for interchanging data with other systems and for saving objects to localStorage and databases. ''string'' is the string to be converted. ''reviver'' is an optional function name that can be used to do some processing of the data while being parsed.


'''Example'''
== Example ==


<pre>
<pre>
REM JSON.PARSE Example
Rem Json.Parse Example
myObject=JSON.parse(s, reviver)
myObject=Json.Parse(s, reviver)
Print "myObject.a:" & myObject.a & " myObject.b:" & myObject.b
Print "myObject.a:" & myObject.a & " myObject.b:" & myObject.b
   
   
Line 21: Line 21:
</pre>
</pre>


'''Output'''
== Output ==


<pre>
<pre>
Line 27: Line 27:
</pre>
</pre>


'''Related Items'''
== Related Items ==


[[json.stringify|JSON.STRINGIFY]]
[[json.stringify|JSON.STRINGIFY]]
[[Category:Language Reference]]

Revision as of 01:52, 17 August 2012

Json.Parse (string[, reviver])

Description

Json.Parse converts a string created by JSON.STRINGIFY into an NS Basic object. It is useful for interchanging data with other systems and for saving objects to localStorage and databases. string is the string to be converted. reviver is an optional function name that can be used to do some processing of the data while being parsed.

Example

Rem Json.Parse Example
myObject=Json.Parse(s, reviver)
Print "myObject.a:" & myObject.a & " myObject.b:" & myObject.b
 
Function reviver(key, value)
  If key="a" and TypeName(Value)= "Integer" Then 
    reviver=CStr(value) 'If value is a number, we want to change it to string.
  Else
    reviver=value
  End If
End Function

Output

myObject.a:12355 myObject.b:4

Related Items

JSON.STRINGIFY