2013-01-16 41 views
0

我有一个SounCloud PHP包装的问题。当我向SounCloud API发出一个Oembed请求时。这最后一个给我一个字符串数据。它由类似标题和JSON数据组成。它看起来像这样:SoundCloud API:我无法解码Json数据

Age: 0 
Via: 1.1 varnish 
X-Cache: MISS 
Vary: Accept-Encoding 

{"version":1.0,"type":"rich",......."author_url":"https://soundcloud.com/forss"} 

所以,当我使用json_decode功能此数据,无法解码JSON的一部分。 有没有人有任何想法如何从这个内容删除标题?

注:我的工作背后的代理,所以我必须添加下面这段代码,使卷曲请求工作

$client->setCurlOptions(array(
      CURLOPT_FOLLOWLOCATION => 1, 
     CURLOPT_PROXY => "http://xxxxxxxxxx", 
     CURLOPT_PROXYPORT => 8080, 
     CURLOPT_PROXYUSERPWD => "xxxx:xxxx", 
     CURLOPT_SSL_VERIFYPEER => 0)); 

回答

0

真奇怪!你可以做的是:

if(strstr($response, "{") !== false){ 
    $response = substr($response, strstr("{")); 
} 
+0

谢谢。 我给自己定了CURLOPT_HEADER为false,并添加固定在的SoundCloud PHP包装里的句子: 如果(!array_key_exists(CURLOPT_HEADER,$选项)&& $选项[CURLOPT_HEADER]) \t $此 - > _ lastHttpResponseBody = $的数据; else $ this - > _ lastHttpResponseBody = substr($ data,$ info ['header_size']); – user1697015