BCLtd BCLtd - 1 year ago 103
JSON Question

JSON - PHP - Reading Key

I have the following code below, which I am trying to run to save the key in the json to a PHP varible. However, for some reason it's just not doing anything - although it seems my code is right, any ideas where I am going wrong?

$json = file_get_contents('url');
$data = json_decode($json,true);

$id = $data['s_id'];



and the json from the external URL looks like this


Answer Source

You have an array wrapping the object

$id = $data[0]['s_id'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download