1

PHP と json_decode を使用して JSON ファイルを解析しようとしていますが、返された JSON が名前空間である場合、これを行うのが困難です。例えば:

$json_ouput = json_decode($json);

foreach ( $json_ouput->feed as $feed) {

   /*
     Here is the problem, $feed contains a namespaced key
     $feed->ab:test->value // Does not work :(
   */
}

ここで最善の解決策は何ですか?

4

2 に答える 2

4

いつもと同じ。

$feed->{'ab:test'}->value
于 2012-05-30T04:37:36.367 に答える
0

変数と周囲の文字列文字の間のあいまいさを取り除くのとほぼ同じ方法で、アクセサの一部を使用{してパッチを適用できます。}

$json = '{"feed":[{"ab:test":{"value":"foo"}},{"ab:test":{"value":"bar"}}]}';
$json_output = json_decode( $json );

foreach ( $json_output->feed as $feed ) {

  // Outputs: foo bar
  print_r( $feed->{'ab:test'}->value );

}

デモ:http ://codepad.org/MYYwOJj2

于 2012-05-30T04:51:28.947 に答える