[ create a new paste ] login | about

Link: http://codepad.org/d4nMRwmk    [ raw code | output | fork ]

martin@mustbebuilt.co.uk - PHP, pasted on Dec 5:
1
2
3
4
5
6
7
8
9
10
<?php
$myJson = '{"Guitar":"Johnny","Vocals":"Stephen","Bass":"Andy","Drums":"Mike"}';
$myArray = json_decode($myJson, true);
print_r($myArray);
echo "{$myArray ['Vocals']}/n";
// and as an object
$myObject = json_decode($myJson);
print_r($myObject);
echo $myObject->Guitar;
?>


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Array
(
    [Guitar] => Johnny
    [Vocals] => Stephen
    [Bass] => Andy
    [Drums] => Mike
)
Stephen/nstdClass Object
(
    [Guitar] => Johnny
    [Vocals] => Stephen
    [Bass] => Andy
    [Drums] => Mike
)
Johnny


Create a new paste based on this one


Comments: