获取特定整数元素的对象[重复]

This question already has an answer here:

$ActionData = '{"1":"muk",
                    "2":"goy",
                    "3":"sag",
                    "formname":"leadform1",
                    "skip":"true"
                  }';
    $form_field = json_decode($ActionData);
    print_r($form_field);
    echo $form_field->1;

I have an error on echo $form_field->1; what am i making mistake there

</div>

just add true in your code like

$form_field = json_decode($ActionData, true);

it works for me

use json_deocde with true as second parameter and access the associative array.

$ActionData = '{"1":"muk",
                    "2":"goy",
                    "3":"sag",
                    "formname":"leadform1",
                    "skip":"true"
                  }';
    $form_field = json_decode($ActionData, true);
    echo $form_field[1]; //muk

Also you can do it using the curly braces as Pupil suggest.

Use curly braces.

echo $form_field->{1};

Total Program:

<?php
$ActionData = '{"1":"muk",
                    "2":"goy",
                    "3":"sag",
                    "formname":"leadform1",
                    "skip":"true"
                  }';
$form_field = json_decode($ActionData);
echo '<pre>';
print_r($form_field);
echo '</pre>';

echo '<pre>';
echo $form_field->{1};
echo '</pre>';
?>

Output:

stdClass Object
(
    [1] => muk
    [2] => goy
    [3] => sag
    [formname] => leadform1
    [skip] => true
)

muk

Access the element as below.

echo $form_field['1'];