0

I try to read IME field in PHP from following JSON FORMAT:

{"komentarji": [ {"RC_KOMENTARJI": [ {
          "K_ID": 101,
          "STATUS": "A",
          "IME": "boris",
          "E_MAIL": "[email protected]",
          "KOMENTAR": "testni vnos",
          "IP": "10.0.0.6",
          "DATUM_ZAPISA": "2016-12-03T23:23:47Z",
          "DATUM_UREJANJA": "2016-12-03T23:24:01Z"
        },
        {
          "K_ID": 1,
          "STATUS": "A",
          "IME": "Peter",
          "KOMENTAR": "Zelo profesionalno ste opravili svoje delo.",
          "IP": "10.0.0.8",
          "DATUM_ZAPISA": "2011-05-04T00:00:00Z"
        }
      ] } ] }

How can I reach that field via foreach in PHP? Thank you.

1

3 Answers 3

1

Let you decode the json to object named $result.

If you want to read first IME then try this

$result->komentarji[0]->RC_KOMENTARJI[0]->IME

If you want to read all IME then you have to apply loop throw komentarji and RC_KOMENTARJI

Sign up to request clarification or add additional context in comments.

Comments

0

Decode it by using json_decode().

$object = json_decode($json);
// result in object
$array =  json_decode($json, true);
// result in array 

Comments

0

You can try this:

$array = json_decode($json, true);

foreach ($array['komentarji'] as $key => $value) {
    foreach ($value['RC_KOMENTARJI'] as $k => $val) {
        echo $val['IME'] . "<br/>";
    }
}

This will print:

boris
Peter

Hope it helps!!!

Comments

Your Answer

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.