-1

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
asked Jul 3, 2016 at 6:02
3
  • 1
    use json_decode() function of PHP and loop through the result array. Commented Jul 3, 2016 at 6:04
  • Try this example: https://3v4l.org/6d1dV, Here you found both resultant array and value access. Commented Jul 3, 2016 at 6:07
  • 1
    Possible duplicate of How to parse JSON in PHP Commented Nov 14, 2016 at 21:54

2 Answers 2

1

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

0

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.