I am parsing this JSON data in Java. I do have basic knowledge of PHP but I am unable to parse this JSON data with PHP, can someone help me do so?
my_jsonEncode.json
{
"server_response": [
{
"error": true,
"instId": "1",
"instName": "abc",
"instDescription": "my description",
"instLogo": "web.com/image/mylogo.jgp"
}
]
}
halfer
20.1k19 gold badges110 silver badges207 bronze badges
2 Answers 2
Try this :
$json = '{
"server_response": [
{
"error": true,
"instId": "1",
"instName": "abc",
"instDescription": "my description",
"instLogo": "web.com/image/mylogo.jgp"
}
]
}';
$result = json_decode ($json);
echo $result->server_response[0]->instId.' ';
echo $result->server_response[0]->instName.' ';
echo $result->server_response[0]->instDescription.' ';
echo $result->server_response[0]->instLogo.' ';
Edit: It convert Json to php object. Since there is only on Json array, you can get directly the element. If you have more array inside of Json then you can foreach each $result->server_response. For example :
foreach($result->server_response as $item)
answered Jul 3, 2016 at 6:18
Comments
Php has two build-in functions (mainly) to work with JSON this are:
- json_encode(param)
- json_decode();
The later one return an associative array with the key value pairs.
answered Jul 3, 2016 at 6:08
Comments
lang-php
json_decode()
function of PHP and loop through the result array.