2012-04-25 6 views
0

私はいくつかのJSONデータを扱うPHPスクリプトを書いています。以下は(簡略化した)var_dump($data)です。私は["[question(13), option(0)]"]という値20を返したいと思います。私はそれを行う方法を理解できません。私は$data->[question(13), option(0)]$data->question(13)を試しました。 (私はこれを見上げてみましたが、私は表記が何を意味するのかわからないので、私は私が探しているかわからないんだけど)PHPは配列の中にオブジェクト変数を返します

object(stdClass)#133 (36) { 
    ["id"]=> 
    string(1) "1" 
    ["contact_id"]=> 
    string(0) "" 
    ["status"]=> 
    string(8) "Complete" 
    ["is_test_data"]=> 
    string(1) "0" 
    ["datesubmitted"]=> 
    string(19) "2012-04-19 17:11:00" 
    ["[question(5)]"]=> 
    string(11) "C. 40%, 40%" 
    ["[question(9)]"]=> 
    string(47) "D. EBITDA and Free cash flow are the same thing" 
    ["[question(10)]"]=> 
    string(48) "A. Accounts Payable as % of sales would increase" 
    ["[question(11)]"]=> 
    string(20) "E. None of the above" 
    ["[question(12)]"]=> 
    string(97) "A.  A larger portion of initial investment is equity which can increase exit return potential." 
    ["[question(13), option(0)]"]=> 
    string(2) "20" 
    ["[url("embed")]"]=> 
    string(0) "" 
    ["[variable("STANDARD_IP")]"]=> 
    string(13) "38.107.74.230" 
    ["[variable("STANDARD_LONG")]"]=> 
    string(10) "-73.976303" 
    ["[variable("STANDARD_LAT")]"]=> 
    string(9) "40.761902" 
} 
+0

を試してみてください。 –

答えて

3

どちらの拡張オブジェクトアクセスの表記を使用します。

$data->{'[question(13), option(0)]'} 

通常の配列を求めて、通常の配列として使用してください。

json_decode($json, true); 
+0

非常に良い答えです。それをより良く言うことはできませんでした。 – powtac

+0

ああ...悪名高い中括弧。ありがとう! 好奇心の外に、その記法は何を意味していますか?それらのインスタンス変数はオブジェクトですか? – emersonthis

+0

@エマーソン:はい、そうです。詳細については、http://stackoverflow.com/questions/3737139/reference-what-does-this-symbol-mean-in-phpをご覧ください。 – xfix

1

あなたが本当にあなたの特性が共通の変数名の規則に従わなければならない。この

echo $data->{'[question(13), option(0)]'}; 
関連する問題