2012-07-21 115 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”的未知键)。