-3

I am unable to get values of array of this json... how can i have all these values seperately!!

{
    "id": "jai",
    "pwd": "123",
    "user": [
        {
            "fname": "jai",
            "lname": "gupta"
        },
        {
            "fname": "sameer",
            "lname": "seth"
        }
    ],
    "college": "vit"
}
Thaillie
  • 1,362
  • 3
  • 17
  • 31

3 Answers3

1
$myArray = json_decode($json, true);

var_dump($myArray['id']);
var_dump($myArray['user'][0]['fname']);
Mihai Matei
  • 24,166
  • 5
  • 32
  • 50
0

You can access each "value" by accessing regular php array key value pairs.

$jsonn = '{"id":"jai","pwd":"123","user":[{"fname":"jai","lname":"gupta"},{"fname":"sameer","lname":"seth"}],"college":"vit"}';
$new = json_decode($jsonn, true);

$id = $new['id'];
$user = $new['user'];
..... and so on.

Hope this helps.

Cheers!

bIgBoY
  • 417
  • 2
  • 12
0

You can decode these values from json to object.

$result = json_decode('{"id":"jai","pwd":"123","user":[{"fname":"jai","lname":"gupta"},{"fname":"sameer","lname":"seth"}],"college":"vit"}');

and acccess like below:

$result->id; 
$result->pwd;
vaths
  • 73
  • 6