0

I am using curl function to get the data from gotowebinar url. here is the code

 $data=curl_exec($curl);


   @curl_close($curl);

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

I am getting this output:

[
    {
        "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"
    }
]

I used json_decode to format the data but it did not work. I want to format the output so that I can use its values in program.

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 回答