1

运行 curl 后,我得到一个 json 对象列表,我需要将其转换为 PHP 数组。当我使用 json_decode 它返回一个 NULL 值。然后我使用 Json 验证器检查 json 结果,然后它在 json 中显示错误。

这是 CUrl 代码

    $ch = curl_init();
    curl_setopt_array($ch, array(
        CURLOPT_URL => $stream_url,
        CURLOPT_ENCODING => "gzip",
        CURLOPT_FOLLOWLOCATION => true,
        CURLOPT_HTTPAUTH => CURLAUTH_BASIC,
       // CURLOPT_TIMEOUT => 120,
        CURLOPT_USERPWD => $user . ":" . $pass,
        CURLOPT_WRITEFUNCTION => "print_out_data",
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_VERBOSE => true // uncomment for curl verbosity

    ));

    $running = null;

    $mh = curl_multi_init();
    curl_multi_add_handle($mh, $ch);

    // the event loop
     $listarray= array();

    do {
        curl_multi_select($mh, 1); // wait for activity
        curl_multi_exec($mh, $running); // perform activity
        $content = curl_multi_getcontent($ch);


    } while ($running > 0);

    curl_multi_remove_handle($mh, $ch);
    curl_multi_close($ch);

    $new = json_decode($content,true)

    print_r($new);

这是我打印 $content 时得到的 Json 结果

{"id":"tag:search.twitter.com,2005:307097936616116227","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:111054522","link":"http://www.twitter.com/Adobe_Care","displayName":"Adobe Customer Care","postedTime":"2010-02-03T17:16:58.000Z","image":"http://a0.twimg.com/profile_images/2649331561/0a1bbf035e7e66164b2514470a6a6a00_normal.png","summary":"Official Customer Support account for Adobe | \r\nTweeting M-F 1a-5p PST | Have feedback? http://bit.ly/socialfbs | Need additional help? http://forums.adobe.com","links":[{"href":null,"rel":"me"}],"friendsCount":1508,"followersCount":9235,"listedCount":353,"statusesCount":16807,"twitterTimeZone":"Eastern Time (US & Canada)","verified":true,"utcOffset":"-18000","preferredUsername":"Adobe_Care","languages":["en"]},"verb":"post","postedTime":"2013-02-28T12:00:28.000Z","generator":{"displayName":"Sprout Social","link":"http://sproutsocial.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/Adobe_Care/statuses/307097936616116227","body":"@maconnolly888 AdobeTV has some great tutorials - http://t.co/1BEJBLOGJG Thanks, ^Bev","object":{"objectType":"note","id":"object:search.twitter.com,2005:307097936616116227","summary":"@maconnolly888 AdobeTV has some great tutorials - http://t.co/1BEJBLOGJG Thanks, ^Bev","link":"http://twitter.com/Adobe_Care/statuses/307097936616116227","postedTime":"2013-02-28T12:00:28.000Z"},"inReplyTo":{"link":"http://twitter.com/maconnolly888/statuses/306915834578751488"},"twitter_entities":{"hashtags":[],"urls":[{"url":"http://t.co/1BEJBLOGJG","expanded_url":"http://adobe.ly/YIz8Eg","display_url":"adobe.ly/YIz8Eg","indices":[50,72]}],"user_mentions":[{"screen_name":"maconnolly888","name":"martin connolly","id":17490272,"id_str":"17490272","indices":[0,14]}]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"from:111054522","tag":null}],"urls":[{"url":"http://t.co/1BEJBLOGJG","expanded_url":"http://tv.adobe.com/show/learn-creative-cloud/"}],"klout_score":60,"language":{"value":"en"}}} {"id":"tag:search.twitter.com,2005:307098755235184640","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:74614502","link":"http://www.twitter.com/TheNextWebAsia","displayName":"TheNextWeb Asia","postedTime":"2009-09-16T01:13:07.000Z","image":"http://a0.twimg.com/profile_images/1108109662/tnwasia_twitter_normal.png","summary":"Part of @thenextweb family here you will find the latest tech news from Asia. Updates from @jonrussell and @beijingdou","links":[{"href":"http://thenextweb.com/asia","rel":"me"}],"friendsCount":1123,"followersCount":4734,"listedCount":327,"statusesCount":2520,"twitterTimeZone":"Bangkok","verified":false,"utcOffset":"25200","preferredUsername":"TheNextWebAsia","languages":["en"],"location":{"objectType":"place","displayName":"Asia"}},"verb":"post","postedTime":"2013-02-28T12:03:43.000Z","generator":{"displayName":"TwitPublisher","link":"http://wordpress.org/extend/plugins/twitter-publisher/"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/TheNextWebAsia/statuses/307098755235184640","body":"Tencent focuses on Indonesia with local joint venture to promote its WeChat mobile app http://t.co/UggpJQHzPa by @jonrussell","object":{"objectType":"note","id":"object:search.twitter.com,2005:307098755235184640","summary":"Tencent focuses on Indonesia with local joint venture to promote its WeChat mobile app http://t.co/UggpJQHzPa by @jonrussell","link":"http://twitter.com/TheNextWebAsia/statuses/307098755235184640","postedTime":"2013-02-28T12:03:43.000Z"},"twitter_entities":{"hashtags":[],"urls":[{"url":"http://t.co/UggpJQHzPa","expanded_url":"http://tnw.to/r1kJ","display_url":"tnw.to/r1kJ","indices":[87,109]}],"user_mentions":[{"screen_name":"jonrussell","name":"Jon Russell","id":6132422,"id_str":"6132422","indices":[113,124]}]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"from:74614502","tag":null}],"urls":[{"url":"http://t.co/UggpJQHzPa","expanded_url":"http://thenextweb.com/asia/2013/02/28/tencent-focuses-on-indonesia-with-local-joint-venture-to-promote-its-wechat-mobile-app/?utm_source=Twitter&utm_content=Tencent+focuses+on+Indonesia+with+local+joint+venture+to+promote+its+WeChat+mobile+app&utm_campaign=social+media&awesm=tnw.to_r1kJ&utm_medium=Twitter+Publisher"}],"klout_score":57,"language":{"value":"en"}}} {"id":"tag:search.twitter.com,2005:307099167946313728","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:31175695","link":"http://www.twitter.com/ProntoForms","displayName":"ProntoForms","postedTime":"2009-04-14T17:36:42.000Z","image":"http://a0.twimg.com/profile_images/1606516105/ProntoAppIcon-200x200_normal.png","summary":"ProntoForms is a simple to use mobile forms app for iPhones, Blackberry, Android, and Windows Mobile devices. Try it today!","links":[{"href":"http://www.prontoforms.com","rel":"me"}],"friendsCount":459,"followersCount":369,"listedCount":3,"statusesCount":1576,"twitterTimeZone":"Eastern Time (US & Canada)","verified":false,"utcOffset":"-18000","preferredUsername":"ProntoForms","languages":["en"],"location":{"objectType":"place","displayName":"Ottawa, Canada"}},"verb":"post","postedTime":"2013-02-28T12:05:21.000Z","generator":{"displayName":"HootSuite","link":"http://www.hootsuite.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/ProntoForms/statuses/307099167946313728","body":"Thanks for following @jennzmitchell","object":{"objectType":"note","id":"object:search.twitter.com,2005:307099167946313728","summary":"Thanks for following @jennzmitchell","link":"http://twitter.com/ProntoForms/statuses/307099167946313728","postedTime":"2013-02-28T12:05:21.000Z"},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"jennzmitchell","name":"Jennifer Mitchell","id":210779450,"id_str":"210779450","indices":[21,35]}]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"from:31175695","tag":null}],"klout_score":40,"language":{"value":"en"}}} 
4

0 回答 0