2012-07-21 114 views
0

你好我試圖解析從谷歌地圖API這個結果,解析編碼的JSON字符串

{tooltipHtml:" (10.6 km/15 mins)",polylines:[{id:"route0",points:"}[email protected]@??fCmA??MmDEqIHkGViHlHq`A??}[email protected]}OcP{OkOgCiCQ[cBuA??kIuE_S_KeEmDwA{B{EyIyDmHuFgL_CaIYuA?W[[email protected][email protected][email protected]@[email protected][B{[email protected]{DZaB\\[email protected]@[email protected]@[email protected][yH[[email protected]?sB\\[email protected]@K??[fB??{TfIgBbAwFzD??XjBVX?X",levels:"[email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected][email protected]??????????????BBBB??BB??B",numLevels:4,zoomFactor:16}]} 

但Restkit不會接受編碼點,給我這個錯誤

E restkit.network:RKResponse.m:289 Unable to parse response body: Unexpected token, wanted '{', '}', '[', ']', ',', ':', 'true', 'false', 'null', '"STRING"', 'NUMBER'. 

我代碼看起來像下面解析結果

- (void)request:(RKRequest*)request didLoadResponse:(RKResponse*)response { 

NSError *error = nil; 

NSDictionary *parsedResponse = [response parsedBody:&error]; 

回答

2

我認爲,答案的格式不是JSON。在JSON格式中,鍵被置於引號中:「」。

見真JSON的例子:{ 「KEY1」: 「KEY2」 5: 「STRING_VALUE」}

或者看到真正的JSON從谷歌服務的例子:

{ 「狀態」: 「OK」, 「成果」:[{ 「類型」:STREET_ADDRESS, 「的formatted_address」:「1600劇場P KWY,山景,CA 94043,USA」, 「address_components」:[{ 「LONG_NAME」: 「1600」, 「簡稱的」: 「1600」, 「類型」:street_number },{ 「LONG_NAME」 : 「劇場100號」, 「簡稱的」: 「劇場100號」, 「類型」:路線 },{ 「LONG_NAME」: 「山景」, 「簡稱的」: 「山景」, 「類型」 :[「locality」,「political」] },{ 「long_name」:「California」, 「short_name」:「CA」, 「types」:[「administrative_area_level_1」,「political」] },{ 「LONG_NAME」: 「美的」, 「簡稱的」: 「US」, 「類型」: 「國家」, 「政治」] },{ 「LONG_NAME」: 「94043」, 「SHORT_NAME」 : 「94043」, 「類型」:POSTAL_CODE }], 「幾何」:{ 「位置」:{ 「LAT」:37.4219720, 「LNG」:-122.0841430 }, 「LOCATION_TYPE」:「 ROOFTOP 「 」視口「:{ 」西南「:{ 」LAT「:37.4188244, 」LNG「:-122.0872906 }, 」 northea ST「:{ 」LAT「:37.4251196, 」LNG「:-122.0809954 }} } } ] }

資料來源:https://developers.google.com/maps/documentation/geocoding/?hl=ru#JSON

爲了測試我的JSON我通常使用http://json.parser.online.fr/(但是對於Google的示例回答,它不能正常工作,導致名爲「type」的未知鍵)。