0

OAuth を使用して Yahoo クエリ言語からいくつかのメールを取得しようとしています。YQL が JSON を返し、どういうわけかそれを解析できないことを除いて、すべて問題ありません。

次のような単純な JSON を解析できます

'{"hello":"world"}'

しかし、これではありません:

{
"query": {
    "count": 1,
    "created": "2012-08-11T19:22:51Z",
    "lang": "en-US",
    "results": {
        "result": {
            "messageInfo": [
                {
                    "from": {
                        "name": "account-services-us@cc.yahoo-inc.com"
                    },
                    "subject": "Success! You have shared your Yahoo! information"
                },
                {
                    "from": {
                        "name": "account-services-in@cc.yahoo-inc.com"
                    },
                    "subject": "Success! You have shared your Yahoo! information."
                },
                {
                    "from": {
                        "name": "account-services-in@cc.yahoo-inc.com"
                    },
                    "subject": "Success! You have shared your Yahoo! information."
                },
                {
                    "from": {
                        "name": "Yahoo!"
                    },
                    "subject": "Welcome to Yahoo!"
                }
            ]
        }
    }
}
}

http://jsonlint.com/で検証してみました

そしてそれは有効です!

編集:「from:name」と「subject」をテーブルのような構造で表示する必要があります。

私が書いたコードスニペットは次のとおりです。

$sdata = call_yql(OAUTH_CONSUMER_KEY, OAUTH_CONSUMER_SECRET,
               $access_token, $access_token_secret,
               false, true);
$json_data = json_encode($sdata);
$mails = json_decode($json_data);
print_r($mails->query);

私が得るエラーは次のとおりです。

Notice: Trying to get property of non-object in C:\xampp\htdocs\yahoo\txtweb\yql.php       on line 21
4

1 に答える 1

0

この URL を参照してください:-

PHPでJSONファイルを解析する

こちらのURLもご覧ください

http://collegewires.com/parsing-json-with-php/

または試してみてください

多次元配列をイテレータするには、 RecursiveArrayIteratorを使用できます

$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($json, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
    if(is_array($val)) {
        echo "$key:\n";
    } else {
        echo "$key => $val\n";
    }
}
于 2012-08-11T19:55:46.367 に答える