phpdev phpdev - 1 year ago 66
JSON Question

how to retrieve data from json in json

I have following code in my contoller:

public function actionForm($id)
$decodedJson=json_decode($jsonfile->json, true);
return $decodedJson;

Here json ( in $jsonfile->json) is name of the field in ChForms.
When I wrote `var_dump($decodedJson);, it showed the data below:

array(38) { ["name"]=> string(10) "membership" ["view"]=> string(14) "pdf/membership" ["phone"]=> string(5) "22222"

I am going to display it in the following way:

name: membership
view: pdf/membership
phone: 22222

How can I do it?

Answer Source

You can use foreach():

foreach ($decodedJsonas as $key => $value) {
        echo "$key: $value \n";

You can see how it works below:

PHP Compiler

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download