A basic PHP example:
$raw = '{
"A_B" : {
"id" : 7,
"last" : "0.00000038"
},
"A_C" : {
"id" : 8,
"last" : "0.00001938"
}
}';
// Translate from JSON to data object
$data = json_decode($raw);
// Read variables from the data object
echo 'Option 1)<br />
data->A_B->id = '.$data->A_B->id.'<br />
data->A_B->last = '.$data->A_B->last.'<br />';
// Extract and read a single object
$c = $data->A_B;
echo 'Option 2)<br />
c->id = '.$c->id.'<br />
c->last = '.$c->last.'<br />';
// To an array version. Note: 'true' is included
$ar = json_decode($raw, true);
// Reading a array
echo 'Option 3)<br />
ar[A_B][id] = '.$ar['A_B']['id'].'<br />
ar[A_B][last] = '.$ar['A_B']['last'].'<br />';
// And finally, I think what you have done
$c = $ar['A_B'];
echo 'Option 4)<br />
c[id] = '.$c['id'].'<br />
c[last] = '.$c['last'].'<br />';
Which will render the following:
Option 1)
data->A_B->id = 7
data->A_B->last = 0.00000038
Option 2)
c->id = 7
c->last = 0.00000038
Option 3)
ar[A_B][id] = 7
ar[A_B][last] = 0.00000038
Option 4)
c[id] = 7
c[last] = 0.00000038
Edit. I think I understand what you are after. See the following updated PHP script.
$raw = '{
"A_B" : {
"id" : 7,
"last" : "0.00000038"
},
"A_C" : {
"id" : 8,
"last" : "0.00001938"
}
}';
// Only interested in these valves from the JSON
// Value 'X_Y`' is expected to fail!
$knownId = array('A_C','X_Y');
// Extract JSON to array
$c = json_decode($raw,true);
// Only print values that match $knownId
foreach($knownId as $k => $v) {
if ($c[$v]) {
echo '<p>v:['.$v.']
id:['.$c[$v]['id'].']
last:['.$c[$v]['last'].']</p>';
}
}
Which would display a single result from the sample data in $raw.
v:[A_C] id:[8] last:[0.00001938]
A_Bor id of all the elements?