I have a JSON object below, but i'm struggling to get name, value from it.
I would want to get the values and save them into a database.
$json = '
{
"Body":
{
"stkCallback":
{
"ResultCode":0,
"ResultDesc":"The service request is processed successfully.",
"CallbackMetadata":
{
"Item":
[
{
"Name":"Amount",
"Value":10
},
{
"Name":"TransactionDate",
"Value":20170727154800
},
{
"Name":"PhoneNumber",
"Value":26721566839
}
]
}
}
}
}';
How can I get the "Name":"Amount" values and "Name":"TransactionDate" value.
At least for the rest
$ResultCode = json_decode($json)->Body->stkCallback->ResultCode;
$ResultDesc = json_decode($json)->Body->stkCallback->ResultDesc;
The question is, how do I get the values in a loop when some have values and others don't?