JSON: Difference between revisions
Content deleted Content added
mNo edit summary |
added php |
||
Line 9: | Line 9: | ||
var sample = { "blue": [1,2], "ocean": "water" }; |
var sample = { "blue": [1,2], "ocean": "water" }; |
||
var json_string = JSON.stringify(sample);</lang> |
var json_string = JSON.stringify(sample);</lang> |
||
=={{header|PHP}}== |
|||
<lang php><?php |
|||
$data = json_decode('{ "foo": 1, "bar": [10, "apples"] }'); // dictionaries will be returned as objects |
|||
$data2 = json_decode('{ "foo": 1, "bar": [10, "apples"] }', true); // dictionaries will be returned as arrays |
|||
$sample = array( "blue" => array(1,2), "ocean" => "water" ); |
|||
$json_string = json_encode($sample); |
|||
?></lang> |
|||
=={{header|Python}}== |
=={{header|Python}}== |
||
{{works with|Python|2.6+}} |
|||
<lang Python>import json |
<lang Python>import json |
||
data = json.loads('{ "foo": 1, "bar": [10, "apples"] }') |
data = json.loads('{ "foo": 1, "bar": [10, "apples"] }') |