-1

私は次のJsonを持っています

[response] => stdClass Object
    (
        [status] => 1
        [httpStatus] => 200
        [data] => Array
            (
                [0] => 230
                [1] => 1956
                [2] => 1958
                [3] => 2294
   )

応答からデータ配列を取得するにはどうすればよいですか?

私はこれが非常に簡単であることを知っています。

アップデート

これが私のソースコードの一部です

$url = $base . http_build_query( $params );
$result = file_get_contents( $url );

echo '<pre>';
print_r( json_decode( $result ) );
echo '</pre>';
$data = $result->response->data;
print_r($data);
4

3 に答える 3

2
$json_object = json_decode($result);
print_r($json_object->response->data);

PHP では->オブジェクト演算子(または矢印) です。PHPのオブジェクトjson_decode().

于 2013-08-01T14:53:41.520 に答える
1

単にこのように:-

[response] => stdClass Object
    (
        [status] => 1
        [httpStatus] => 200
        [data] => Array
            (
                [0] => 230
                [1] => 1956
                [2] => 1958
                [3] => 2294
   )
$json_data=json_decode($response,true);
于 2013-08-01T14:55:11.737 に答える
1

これは JSON ではなく、PHP の配列またはオブジェクトです。それがどれであるかを判断するのに十分な情報を提供しませんでした。

次のいずれかを使用して、そこからデータ配列にアクセスできます。

$data = $arr['response']->data;

または:

$data = $obj->response->data;

$arror$objを実際の変数名に置き換えます。

編集

変数をデコードした後、結果を保存しなかったため、変数には文字列が含まれています。次のコードを試してください。

$url = $base . http_build_query( $params );
$json = file_get_contents( $url );

$result = json_decode($json);
$data = $result->response->data;

echo '<pre>',print_r($data, true),'</pre>';
于 2013-08-01T14:56:03.860 に答える