2

タイプ text/x-json の応答を取得しようとしています

jsonでデコードします(失敗します)

これは私のコードスニペットです:

<?php

//prepare URL (in this example send WAZE web site a route calculation
$url = "http://www.waze.com/RoutingManager/routingRequest?from=x%3A-73.8876574+y%3A40.7664011+bd%3Atrue&to=x%3A-73.7721035+y%3A40.7486434+bd%3Atrue&returnJSON=true&returnGeometries=true&returnInstructions=true&timeout=60000&nPaths=2";

//send GET request to WAZE web site 
$response = file_get_contents($url);

//All this isnt working 
//$response = utf8_encode($response);
//$response = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $response);
//$response = preg_replace('/.+?({.+}).+/','$1',$response);

//go json
$responseJson = json_decode($response);
// this isnt working 2
//$responseJson = json_decode($response,true);

//now $responseJson is null :(

HELP!

?>

これは私が得る応答ヘッダーです:

$http_response_header   Array [6]   
    0   (string:15) HTTP/1.1 200 OK 
    1   (string:25) Content-Type: text/x-json   
    2   (string:35) Date: Sun, 29 Sep 2013 19:36:08 GMT 
    3   (string:19) Server: nginx/1.4.1 
    4   (string:30) X-UA-Compatible: IE=EmulateIE7  
    5   (string:17) Connection: Close   

助けてください

ありがとう

4

2 に答える 2

1

指定された URL から返されたデータは無効な JSON です ( NaNJavaScript オブジェクト リテラルでは有効ですが、JSON では無効な として一部の値が返されます)。エラーを修正するには、ソースを入手する必要があります (または、データをダウンロードした後に自分でパッチを当てる必要があります)。

于 2013-09-29T19:40:29.150 に答える