I'm struggling to parse a simple JSON array, am new to this so trying to learn.
Here's the data:
{"data":[
{"name":"john","id":"123"},
{"name":"dave","id":"345"}
], "other":
{"foo":"bar"}
}
I only want the data information.
Here's what I'm trying (also what else I tried):
$list = json_decode(file_get_contents($jsonURL),true);
foreach ($list as $element){
//$id = $element->data->id; // this didn't work either
//$name = $element->data->name; // this didn't work either
$id = $element[data][id];
$name = $element[data][name];
$message .= $id.' - '.$name.'</br>';
}
Any ideas why it returns nothing?