NSJSONSerialization在iOS中为MapQuest JSON返回null

Spe*_*efy 3 null parsing ios mapquest nsjsonserialization

我试图在iOS中解析mapquest地理编码json,但NSJSONSterilization返回null.我检查了在线json检查器,看起来网址实际上是一个json.

这是代码 NSJSONSerialization

 if(geocodeResponseData)
 {
     NSLog(@"there is response data");
     //this is logged.
 }


 NSDictionary *mapQuestReponse =  [NSJSONSerialization
                                     JSONObjectWithData:geocodeResponseData
                                     options:kNilOptions
                                     error:&error];

 NSLog(@"mapquestreponse %@", mapQuestReponse);
Run Code Online (Sandbox Code Playgroud)

这是JSON为解析而返回的URL.

http://www.mapquestapi.com/geocoding/v1/batch?key=API----KEY----HIDDEN----&callback=renderBatch&outFormat=json&location=14443%20C%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14510%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14550%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14515%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=1480%20S%20De%20Anza%20Blvd,San%20Jose,%20CA%2095129&location=1600%20S%20De%20Anza%20Blvd,San%20Jose,%20CA%2095129&location=18486%20Prospect%20Rd,San%20Jose,%20CA%2095070&location=14572%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=5210%20Prospect%20Rd,San%20Jose,%20CA%2095129&location=1600%20S%20De%20Anza%20Blvd,San%20Jose,%20CA%2095106&location=14480%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=1818%20Saratoga%20Ave,San%20Jose,%20CA%2095129&location=18562%20Prospect%20Rd,Saratoga,%20CA%2095070&location=14560%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14420%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=1075%20S%20De%20Anza%20Blvd,Cupertino,%20CA%2095129&location=18802%20Cox%20Ave,Saratoga,%20CA%2095070&location=6154%20Bollinger%20Rd,San%20Jose,%20CA%2095129&location=14555%20Big%20Basin%20Way,Saratoga,%20CA%2095070&location=14000%20Fruitvale%20Ave,Saratoga,%20CA%2095070
Run Code Online (Sandbox Code Playgroud)

是因为回来NULLutf-8吗?提前致谢

Mat*_*uch 6

将URL粘贴到webBrowser中以查看服务器实际返回的内容.这将是这样的:

renderBatch(
    {"results":[{"locations":[{"latLng":{"lng":-122.032921,"lat":37.258389},"adminArea4":"Santa Clara" ........ }
);
Run Code Online (Sandbox Code Playgroud)

这是JSON包装renderBatch();.这不是真正可解析的JSON.

这是因为您在请求网址中请求回调.&callback=renderBatch从您的请求网址中删除回调参数(),NSJSONSerilization可以毫无问题地反序列化JSON.