针对PHP Array的Json解码不会返回任何结果

问题描述:

经过对Gnip的几项研究,我将它集成到我的应用程序中,并且我设法添加新规则并从Gnip获取流结果,但是现在我在将其转换为PHP数组并显示它针对PHP Array的Json解码不会返回任何结果

我使用了CURLOPT_RETURNTRANSFER => TRUE,为了不打印curl结果并将其存储到一个变量中,并使用json_decode函数对其进行解码,然后打印它但仍然获得一个空白页面。

如果有人能帮助我在此将提前

这里我节省了很大的时间

感谢是我的代码

$ch = curl_init(); 
    curl_setopt_array($ch, array(
     CURLOPT_URL => $stream_url, 
     CURLOPT_ENCODING => "gzip", 
     CURLOPT_FOLLOWLOCATION => true, 
     CURLOPT_HTTPAUTH => CURLAUTH_BASIC, 
     CURLOPT_USERPWD => $user.":".$pass, 
     CURLOPT_WRITEFUNCTION => "print_out_data", 
     CURLOPT_RETURNTRANSFER => TRUE, 
     CURLOPT_LOW_SPEED_TIME=> 60, 
     CURLOPT_TIMEOUT => 10, 

//CURLOPT_VERBOSE => true // uncomment for curl verbosity 

    )); 


    $content = curl_exec($ch); 

    $arr = json_decode($content, true); 
    $foo = $arr['id']; 
    $bar = $arr['objectType']; 

    print_r($foo); 
    print_r($bar); 

结果打印

当我得到
{"id":"tag:search.twitter.com,2005:304468052219662336","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:348088144","link":"http://www.twitter.com/Devin_Giordan0","displayName":"ᎠƎϑᎥИ ᗩИ✞ℍ⚙ИУ","postedTime":"2011-08-03T21:21:01.000Z","image":"http://a0.twimg.com/profile_images/3271229767/481419170edf2c639441ce43cd540f0e_normal.jpeg","summary":"I will see a Million Before I diee\nInstagram-Youngnrecklessss\nFollow me and ill follow back \nFuck what people think, stay real. ","links":[{"href":null,"rel":"me"}],"friendsCount":476,"followersCount":265,"listedCount":0,"statusesCount":2773,"twitterTimeZone":null,"verified":false,"utcOffset":null,"preferredUsername":"Devin_Giordan0","languages":["en"],"location":{"objectType":"place","displayName":"*lyn, Ny"}},"verb":"share","postedTime":"2013-02-21T05:50:15.000Z","generator":{"displayName":"Echofon","link":"http://www.echofon.com/"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/Devin_Giordan0/statuses/304468052219662336","body":"RT @julianneromero1: All I wanna do is make youuu happy ","object":{"id":"tag:search.twitter.com,2005:304448192165076993","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:383846395","link":"http://www.twitter.com/julianneromero1","displayName":"julieeeeee","postedTime":"2011-10-02T16:35:38.000Z","image":"http://a0.twimg.com/profile_images/3259175129/bdd9337b0e266c851a471f7034ca319a_normal.jpeg","summary":"Old enough to know better, young enough to not give a fuck. ✊","links":[{"href":null,"rel":"me"}],"friendsCount":409,"followersCount":483,"listedCount":0,"statusesCount":18986,"twitterTimeZone":"Quito","verified":false,"utcOffset":"-18000","preferredUsername":"julianneromero1","languages":["en"]},"verb":"post","postedTime":"2013-02-21T04:31:20.000Z","generator":{"displayName":"Twitter for iPhone","link":"http://twitter.com/download/iphone"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/julianneromero1/statuses/304448192165076993","body":"All I wanna do is make youuu happy ","object":{"objectType":"note","id":"object:search.twitter.com,2005:304448192165076993","summary":"All I wanna do is make youuu happy ","link":"http://twitter.com/julianneromero1/statuses/304448192165076993","postedTime":"2013-02-21T04:31:20.000Z"},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[]}},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[{"screen_name":"julianneromero1","name":"julieeeeee","id":383846395,"id_str":"383846395","indices":[3,19]}]},"retweetCount":5,"gnip":{"matching_rules":[{"value":"Happy","tag":null}],"klout_score":42,"language":{"value":"en"}}} {"id":"tag:search.twitter.com,2005:304468052492300288","objectType":"activity","actor":{"objectType":"person","id":"id:twitter.com:1192574623","link":"http://www.twitter.com/Krystlegtsi","displayName":"Tracee Pavlik","postedTime":"2013-02-18T09:14:11.000Z","image":"http://a0.twimg.com/profile_images/3271765828/92aae4995378723671641594159a6ad7_normal.jpeg","summary":null,"links":[{"href":"http://tinyurl.com/b23r4ee","rel":"me"}],"friendsCount":20,"followersCount":0,"listedCount":0,"statusesCount":4,"twitterTimeZone":null,"verified":false,"utcOffset":null,"preferredUsername":"Krystlegtsi","languages":["en"]},"verb":"post","postedTime":"2013-02-21T05:50:15.000Z","generator":{"displayName":"web","link":"http://twitter.com"},"provider":{"objectType":"service","displayName":"Twitter","link":"http://www.twitter.com"},"link":"http://twitter.com/Krystlegtsi/statuses/304468052492300288","body":"It was an Amazing event tonight ...and makes me happy to see the president is educated speaks English Mashallah.","object":{"objectType":"note","id":"object:search.twitter.com,2005:304468052492300288","summary":"It was an Amazing event tonight ...and makes me happy to see the president is educated speaks English Mashallah.","link":"http://twitter.com/Krystlegtsi/statuses/304468052492300288","postedTime":"2013-02-21T05:50:15.000Z"},"twitter_entities":{"hashtags":[],"urls":[],"user_mentions":[]},"retweetCount":0,"gnip":{"matching_rules":[{"value":"Happy","tag":null}],"language":{"value":"en"}}} 
+1

你能分享一下$ content变量吗? – Ankit 2013-02-21 05:41:11

+0

如果您在“json_decode”之前打印$内容,您会看到什么?有没有什么回应? – sanandrl 2013-02-21 05:43:00

+0

Ohh打印$内容时我不会得到任何结果但CURLOPT_RETURNTRANSFER => TRUE它会打印出我的json结果,并且现在将结果粘贴到我的问题选项卡 – doubleD 2013-02-21 05:49:52

  1. che ck内容$content
  2. 如果有内容,请检查(print_r($arr)),检查结构并根据它进行打印。
+0

您好,感谢回复,但问题是$ content是空的,不会打印任何东西。 – doubleD 2013-02-21 05:53:19

+0

@doubleD:当我删除“CURLOPT_RETURNTRANSFER => TRUE”时检查你的卷曲 – 2013-02-21 05:54:43

+0

然后它打印结果,并且将结果粘贴到我的问题中 – doubleD 2013-02-21 05:58:35

看来你在在rsult串

只应使用UTF-字符JSON编码/解码功能,具有非UTF字符显示名