JSON: Difference between revisions
Content added Content deleted
(Added PicoLisp) |
(→{{header|Oz}}: added) |
||
Line 34: | Line 34: | ||
However, there is an ambiguity with parsing JavaScript object literals by themselves, where it might be mistakenly interpreted as a block, and the key followed by a colon as a label. To avoid this, remember to surround it in parentheses to force it to be interpreted as an expression: |
However, there is an ambiguity with parsing JavaScript object literals by themselves, where it might be mistakenly interpreted as a block, and the key followed by a colon as a label. To avoid this, remember to surround it in parentheses to force it to be interpreted as an expression: |
||
<lang javascript>var data = eval('(' + '{ "foo": 1, "bar": [10, "apples"] }' + ')');</lang> |
<lang javascript>var data = eval('(' + '{ "foo": 1, "bar": [10, "apples"] }' + ')');</lang> |
||
=={{header|Oz}}== |
|||
With the JSON library from [http://code.google.com/p/oz-code/downloads/list here]: |
|||
<lang oz>declare |
|||
[JSON] = {Module.link ['JSON.ozf']} |
|||
{System.show {JSON.decode "{ \"foo\": 1, \"bar\": [10, \"apples\"] }"}} |
|||
Sample = object(blue:array(1 2) ocean:"water") |
|||
{System.showInfo {JSON.encode Sample}}</lang> |
|||
Output: |
|||
<pre>object(bar:array(10 [97 112 112 108 101 115]) foo:1) |
|||
{"blue":[1,2],"ocean":"water"}</pre> |
|||
=={{header|PHP}}== |
=={{header|PHP}}== |