从数组中获取值

时间:2015-07-12 06:04:31

标签: javascript

如何使用javascript

将fname,lname的值与此数组分开
       "Array
(
    [users] => Array
        (
            [0] => stdClass Object
                (
                    [iduser] => 171
                    [email] => chhdshfh@gmail.com
                    [password] => 123
                    [fname] => cha
                    [lname] => shm
                    [dbth] => 1989-08-19 00:00:00
                    [addone] => aaaaaaaa
                    [addtwo] => cccccccccccc
                    [city] => bbbbbbbbbbbbb
                    [country] => LK
                    [tp] => 0111111111
                    [currency] => LKR
                    [gender] => A
                    [job] => sdfsdf
                )

        )

)
"

这是http响应成功数据对象我希望单独获取值请任何人帮助

1 个答案:

答案 0 :(得分:0)

这应该是一个PHP数组。您应该将其转换为JSON格式并在PHP中设置propreate标头。

<?php
$your_array = array(
        ['users'] => Array
            (
                [0] => stdClass Object
                    (
                        ['iduser'] => 171,
                        ['email'] => 'chhdshfh@gmail.com',
                        ['password'] => 123,
                        ['fname'] => 'cha',
                        ['lname'] => 'shm',
                        ['dbth'] => '1989-08-19 00:00:00',
                        ['addone'] => 'aaaaaaaa',
                        ['addtwo'] => 'cccccccccccc',
                        ['city'] => 'bbbbbbbbbbbbb',
                        ['country'] => 'LK',
                        ['tp'] => 0111111111
                        ['currency'] => 'LKR',
                        ['gender'] => 'A',
                        ['job'] => 'sdfsdf'
                    )

            )
    );

header('Content-type: application/json');
echo json_encode($your_array);