0

JSON を受け取り、PHP を使用していくつかの値を解釈しようとしています。

JSON ダンプのスニペットの例:

["11811"]=>
  object(stdClass)#15 (11) {
    ["parent_area"]=>
    NULL
    ["generation_high"]=>
    int(19)
    ["all_names"]=>
    object(stdClass)#16 (0) {
    }
    ["id"]=>
    int(11811)
    ["codes"]=>
    object(stdClass)#17 (3) {
      ["ons"]=>
      string(2) "08"
      ["gss"]=>
      string(9) "E15000008"
      ["unit_id"]=>
      string(5) "41421"
    }
    ["name"]=>
    string(10) "South East"
    ["country"]=>
    string(1) "E"
    ["type_name"]=>
    string(15) "European region"
    ["generation_low"]=>
    int(1)
    ["country_name"]=>
    string(7) "England"
    ["type"]=>
    string(3) "EUR"
  }

多くの (ネストされた) データがあるため、["name"] where ["type_name"] == 'European region' の値を取得する必要があります。

ありがとう。

4

2 に答える 2

-1

これを試して:

<?php
$json = JSON_decode(str,true);
$arr  = Array();
foreach($json as $f) {
 /* eg. $f = $json["11811"] */
 if($f['type_name'] == 'European region') {
  $arr[] = $f['name'];
 }
}
?>
于 2013-04-16T13:00:42.793 に答える