0

gotowebinar url からデータを取得するために curl 関数を使用しています。ここにコードがあります

 $data=curl_exec($curl);


   @curl_close($curl);

   $newdata=json_decode($data, true);
   print_r($newdata);

私はこの出力を得ています:

[
    {
        "registrantKey": 12345,
        "firstName": "xxx",
        "lastName": "xxx",
        "email": "xxx@yahoo.com",
        "status": "WAITING",
        "registrationDate": "2012-07-11T16:54:11Z",
        "joinUrl": "https://www1.gotomeeting.com/join/123/456",
        "timeZone": "America/New_York"
    },
    {
        "registrantKey": 12345,
        "firstName": "xxx",
        "lastName": "xxx",
        "email": "xxx@yahoo.com",
        "status": "WAITING",
        "registrationDate": "2012-07-05T23:55:23Z",
        "joinUrl": "https://www1.gotomeeting.com/join/123/456",
        "timeZone": "America/New_York"
    },
    {
        "registrantKey": 12345,
        "firstName": "xxx",
        "lastName": "xxx",
        "email": "xxx@yahoo.com",
        "status": "WAITING",
        "registrationDate": "2012-07-11T23:27:56Z",
        "joinUrl": "https://www1.gotomeeting.com/join/123/456",
        "timeZone": "America/Chicago"
    },
    {
        "registrantKey": 12345,
        "firstName": "xxx",
        "lastName": "xxx",
        "email": "xxx@visioninvesting.com",
        "status": "WAITING",
        "registrationDate": "2012-07-11T23:29:40Z",
        "joinUrl": "https://www1.gotomeeting.com/join/123/456",
        "timeZone": "America/Chicago"
    },
    {
        "registrantKey": 12345,
        "firstName": "xxx",
        "lastName": "xxx",
        "email": "xxx@yahoo.com",
        "status": "WAITING",
        "registrationDate": "2012-07-11T18:14:32Z",
        "joinUrl": "https://www1.gotomeeting.com/join/123/456",
        "timeZone": "America/Chicago"
    },
    {
        "registrantKey": 12345,
        "firstName": "test",
        "lastName": "1",
        "email": "xxx@yahoo.com",
        "status": "WAITING",
        "registrationDate": "2012-06-29T21:07:10Z",
        "joinUrl": "https://www1.gotomeeting.com/join/123/456",
        "timeZone": "America/Denver"
    }
]

以前json_decodeはデータをフォーマットしていましたが、うまくいきませんでした。プログラムでその値を使用できるように、出力をフォーマットしたいと考えています。

4

2 に答える 2

1

を呼び出した結果のオブジェクトをループするための簡単な PHP コードを次に示しますjson_decode

$newdata = json_decode($data);

foreach($newdata as $entry) {
    echo "{$entry->firstName} is {$entry->status}.  " .
         "Their key is {$entry->registrantKey}.<br />\n";
}

デコードされたオブジェクトから返された json に表示される任意のプロパティにアクセスできます。

オブジェクトの配列を取得するため、(上記のように) 各エントリをループするか、次のように特定のエントリにアクセスできます。

$third = $newdata[2]->firstName;

始めるのに役立つことを願っています。

于 2012-07-24T22:52:35.923 に答える
0

最初に配列に変換してみてください:

$newdata = (array) json_decode($data, true);
于 2012-07-24T23:53:08.233 に答える