php - Decoding JSON array -
i'm struggling parse simple json array, new trying learn.
here's data:
{"data":[ {"name":"john","id":"123"}, {"name":"dave","id":"345"} ], "other": {"foo":"bar"} }
i want data
information.
here's i'm trying (also else tried):
$list = json_decode(file_get_contents($jsonurl),true); foreach ($list $element){ //$id = $element->data->id; // didn't work either //$name = $element->data->name; // didn't work either $id = $element[data][id]; $name = $element[data][name]; $message .= $id.' - '.$name.'</br>'; }
any ideas why returns nothing?
$json = '{"data":[ {"name":"john","id":"123"}, {"name":"dave","id":"345"} ], "other": {"foo":"bar"} }'; $list = json_decode($json,true); foreach ( $list['data'] $item ) { echo $item['id'] . "\n"; echo $item['name'] ."\n\n"; }
here perfect illustration of how work data.
php json
No comments:
Post a Comment