我正在使用google places api来检索用户可以使用自动完成UItableview选择的某些城市的信息。 我的第一个请求给出了一个城市和地区列表,从搜索字符串开始:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=salo&types=(cities)&key=APIKEY
从结果列表中,我将意大利“Salò”的place_id视为一个城市。有了这个id第二个请求:
这是由此产生的json:
{
"html_attributions" : [],
"result" : {
"address_components" : [
{
"long_name" : "Salò",
"short_name" : "Salò",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Salo'",
"short_name" : "Salo'",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Brescia",
"short_name" : "BS",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Lombardia",
"short_name" : "Lombardia",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Italia",
"short_name" : "IT",
"types" : [ "country", "political" ]
}
],
"adr_address" : "\u003cspan class=\"locality\"\u003eSalò\u003c/span\u003e \u003cspan class=\"region\"\u003eBS\u003c/span\u003e, \u003cspan class=\"country-name\"\u003eItalia\u003c/span\u003e",
"formatted_address" : "Salò BS, Italia",
"geometry" : {
"location" : {
"lat" : 45.60839199999999,
"lng" : 10.5104769
},
"viewport" : {
"northeast" : {
"lat" : 45.6146863,
"lng" : 10.5464998
},
"southwest" : {
"lat" : 45.59572439999999,
"lng" : 10.4992233
}
}
},
"icon" : "http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png",
"id" : "f505830b9f7b6886f119df1b07bec0a6785940c7",
"name" : "Salò",
"place_id" : "ChIJdf_ajleOgUcRGniBFh7H884",
"reference" : "CnRtAAAAP9oklxjP8yqebLXhyFK0PM7l_w8zD8eBdNszf67rPHlckKnrhhs66eXZTYHfBiEizetRM8m7e8qxM6otVCX0QvxQ4jXgSv4VcH7NY2ZbYysboNplu8vaFs_BhITJ1MQJ-TunE9L-r1nBavhMLQRKNBIQqsKl1vt_pyqE_7Ow1aXp-hoU9jreecvh94V2ZpHT1JB-DxfoZEI",
"scope" : "GOOGLE",
"types" : [ "locality", "political" ],
"url" : "https://maps.google.com/maps/place?q=Sal%C3%B2+BS,+Italia&ftid=0x47818e578edaff75:0xcef3c71e1681781a",
"vicinity" : "Salò"
},
"status" : "OK"
}
从这个json我需要从administrative_area_level_3中提取值,但我看到一些奇怪的重音,为什么locality long_name值是“Salò”,而administrative_area_level_3 long_name值是“Salo”?这种行为有什么意义?通过这种方式,即使使用utf8编码/解码过程,administrative_area_level_3也会使我的应用程序的uilabel成为“Salo \”...