I have an url passing parameters use json_encode each values like follow:
JavaScript
x
$json = array
(
'countryId' => $_GET['CountryId'],
'productId' => $_GET['ProductId'],
'status' => $_GET['ProductId'],
'opId' => $_GET['OpId']
);
echo json_encode($json);
It’s returned a result as:
JavaScript
{
"countryId":"84",
"productId":"1",
"status":"0",
"opId":"134"
}
Can I use json_decode
to parse each values for further data processing?
Thanks.
Advertisement
Answer
json_decode()
will return an object or array if second value it’s true:
JavaScript
$json = '{"countryId":"84","productId":"1","status":"0","opId":"134"}';
$json = json_decode($json, true);
echo $json['countryId'];
echo $json['productId'];
echo $json['status'];
echo $json['opId'];