-3

ファイルからの次の JSON 出力があります。「SLL」から「最後」をphp変数に抽出するにはどうすればよいですか?

{
   "USD" : {"15m" : 93.89699, "last" : 93.89699, "buy" : 93.25001, "sell" : 93.89698, "24h" : 84.3, "symbol" : "$"},
   "CNY" : {"15m" : 573.0, "last" : 573.0, "buy" : 563.76252, "sell" : 588.11678, "24h" : 572.65, "symbol" : "¥"},
   "JPY" : {"15m" : 9100.0, "last" : 9100.0, "buy" : 9100.0, "sell" : 9150.0, "24h" : 8240.81, "symbol" : "¥"},
   "SGD" : {"15m" : 115.20412, "last" : 115.20412, "buy" : 112.64417, "sell" : 117.51034, 
   "SLL" : {"15m" : 23207.99, "last" : 23207.99, "buy" : 23207.99, "sell" : 23207.99, "24h" : 23207.99, "symbol" : "L$"},  
}
4

6 に答える 6

2

この機能を使用する

json_decode($yourJSONString);

http://php.net/json_decode

于 2013-04-18T13:23:46.380 に答える
1

http://php.net/json_decode

$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';

var_dump(json_decode($json));
var_dump(json_decode($json, true));
于 2013-04-18T13:23:48.520 に答える
1

json 値をデコードする必要があります。

使用する

$decode = json_decode(#your json value#);
echo $decode->SLL->last;
于 2013-04-18T13:27:27.587 に答える
1

これを試して

var_dump(json_decode($json, true));

json オブジェクトの配列をデコードする方法

于 2013-04-18T13:27:40.863 に答える
0
$jsonArr='{
   "USD" : {"15m" : 93.89699, "last" : 93.89699, "buy" : 93.25001, "sell" : 93.89698, "24h" : 84.3, "symbol" : "$"},
   "CNY" : {"15m" : 573.0, "last" : 573.0, "buy" : 563.76252, "sell" : 588.11678, "24h" : 572.65, "symbol" : "¥"},
   "JPY" : {"15m" : 9100.0, "last" : 9100.0, "buy" : 9100.0, "sell" : 9150.0, "24h" : 8240.81, "symbol" : "¥"},
   "SGD" : {"15m" : 115.20412, "last" : 115.20412, "buy" : 112.64417, "sell" : 117.51034}, 
   "SLL" : {"15m" : 23207.99, "last" : 23207.99, "buy" : 23207.99, "sell" : 23207.99, "24h" : 23207.99, "symbol" : "L$"}  
}';

print_r(json_decode($jsonArr));

出力

stdClass Object
(
    [USD] => stdClass Object
        (
            [15m] => 93.89699
            [last] => 93.89699
            [buy] => 93.25001
            [sell] => 93.89698
            [24h] => 84.3
            [symbol] => $
        )

    [CNY] => stdClass Object
        (
            [15m] => 573
            [last] => 573
            [buy] => 563.76252
            [sell] => 588.11678
            [24h] => 572.65
            [symbol] => ¥
        )

    [JPY] => stdClass Object
        (
            [15m] => 9100
            [last] => 9100
            [buy] => 9100
            [sell] => 9150
            [24h] => 8240.81
            [symbol] => ¥
        )

    [SGD] => stdClass Object
        (
            [15m] => 115.20412
            [last] => 115.20412
            [buy] => 112.64417
            [sell] => 117.51034
        )

    [SLL] => stdClass Object
        (
            [15m] => 23207.99
            [last] => 23207.99
            [buy] => 23207.99
            [sell] => 23207.99
            [24h] => 23207.99
            [symbol] => L$
        )

)

これにより、最後に求めたものが得られます

$decodeArr = json_decode($jsonArr);

echo end($decodeArr->SLL);
于 2013-04-18T13:52:46.237 に答える