2016-05-20 12 views
0

私はJSONに慣れていないので、主にPHPを実行します。 MapquestジオコーディングAPIにクエリを実行すると、PHPでjson_decodeしようとすると「NULL」になる次のjson文字列が取得されます。 JSONLintを通してそれを実行JSON構文の問題

renderOptions({ 
    "info": { 
     "statuscode": 0, 
     "copyright": { 
      "text": "\u00A9 2016 MapQuest, Inc.", 
      "imageUrl": "https://api.mqcdn.com/res/mqlogo.gif", 
      "imageAltText": "\u00A9 2016 MapQuest, Inc." 
     }, 
     "messages": [] 
    }, 
    "options": { 
     "maxResults": -1, 
     "thumbMaps": true, 
     "ignoreLatLngInput": false 
    }, 
    "results": [{ 
     "providedLocation": { 
      "street": "Kingston Upon Thames,uk" 
     }, 
     "locations": [{ 
      "street": "", 
      "unknownInput": "", 
      "type": "s", 
      "latLng": { 
       "lat": 51.409628, 
       "lng": -0.306262 
      }, 
      "displayLatLng": { 
       "lat": 51.409628, 
       "lng": -0.306262 
      }, 
      "mapUrl": "https://open.mapquestapi.com/staticmap/v4/getmap?key=na&type=map&size=225,160&pois=purple-1,51.4096275,-0.3062621,0,0,|¢er=51.4096275,-0.3062621&zoom=12&rand=54353" 
     }] 
    }] 
}) 

、私は次のエラーを取得する:

Error: Parse error on line 1: renderOptions({ "in^Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

私は私がしてきた修正が非常に簡単ですが、私はJSONの構文のあまり意識していないよ想像します'renderOptions'の前に物を置いてぼんやりと動く。

問題を修正する正しい構文は何ですか?

+0

http://stackoverflow.com/questions/2887209/what-are-the-differences-between-json-and-jsonp – michaJlS

+1

JSONではなくJSONPが返されています。上のコメントに掲載されたリンクを読んで、代わりにJSONを取り戻す方法に関するMapquestのドキュメントを見てください。 – JAAulde

答えて

0

これは

{ 
    "renderOptions": { 
     "info": { 
      "statuscode": 0, 
      "copyright": { 
       "text": "\u00A9 2016 MapQuest, Inc.", 
       "imageUrl": "https://api.mqcdn.com/res/mqlogo.gif", 
       "imageAltText": "\u00A9 2016 MapQuest, Inc." 
      }, 
      "messages": [] 
     }, 
     "options": { 
      "maxResults": -1, 
      "thumbMaps": true, 
      "ignoreLatLngInput": false 
     }, 
     "results": [{ 
      "providedLocation": { 
       "street": "Kingston Upon Thames,uk" 
      }, 
      "locations": [{ 
       "street": "", 
       "unknownInput": "", 
       "type": "s", 
       "latLng": { 
        "lat": 51.409628, 
        "lng": -0.306262 
       }, 
       "displayLatLng": { 
        "lat": 51.409628, 
        "lng": -0.306262 
       }, 
       "mapUrl": "https://open.mapquestapi.com/staticmap/v4/getmap?key=na&type=map&size=225,160&pois=purple-1,51.4096275,-0.3062621,0,0,|¢er=51.4096275,-0.3062621&zoom=12&rand=54353" 
      }] 
     }] 
    } 
} 
1

有効なJSONこと(renderOptionsを削除します)、どのようなものを括弧内なのは最初の巻き毛で始まり、最後の巻き毛で終わる、JSONです。

+1

OPはこれを第三者APIからの応答として受け取りました... – JAAulde

0

をmapquestジオコーディングサービスのURLに追加すると、パラメータcallback = renderOptionsが設定されます(例:&)。そのパラメータを削除して、コールバックの折り返しを削除します。