-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"
        }
    ]
}
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)
Sign up to request clarification or add additional context in comments.

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.