Google Places API返回的JSON String
有点像这样:
{ "html_attributions" : [], "next_page_token" : "CvQB7AAAAKInrUGS9TZSaskfjkajsfY2CL5gnlli8FaXClYCOfnt6CpDZtSJanUx0OtgZPdXKw9ILf9fqNW1T29gc3mXRZPBKhujEN20qrtYfdfhPubbEHYv6UpKjasf;laskfl;kaTHq1O81Lpr2AwwxlrAX92bKxyky2kXzsVnuUJGO63R58SpEoVOxqMUBvVpxiYljeoRS93VfTib7iaNvwT3JmDeZJMt16b7ID2RUc-OmfjDmJZbikwaaBR_DKlHLjm1FmCvSoUwPQrKp5Lgm0S_pCI6OCnnFnWckYVRIQrkJ4xOC6eVLWVEG16MZmoRoUyWNAKcK6-b6PdLMQQoEY04MSG_o", "results" : [ { "geometry" : { "location" : { "lat" : 94.8793165, "lng" : 17.1700843 }, "viewport" : { "northeast" : { "lat" : 94.8848793, "lng" : 17.1755888 }, "southwest" : { "lat" : 94.8734316, "lng" : 77.1650671 } } }, "icon"
我想将此JSON字符串转换为更合适的类型string[]
。
我试过了
var serializer = new JavaScriptSerializer();
string[] arr = serializer.Deserialize(result,string[]);
但我无法让Deserialize
的第二个参数正确。
请帮帮我。
答案 0 :(得分:1)
编辑:
您的JSON格式错误。如果您使用演示响应进行测试,则表示格式不正确。
以下是格式正确的修改版
{
"html_attributions": [],
"next_page_token": "CpQCAgEAAFxg8o-eU7_uKn7Yqjana-HQIx1hr5BrT4zBaEko29ANsXtp9mrqN0yrKWhf-y2PUpHRLQb1GT-mtxNcXou8TwkXhi1Jbk-ReY7oulyuvKSQrw1lgJElggGlo0d6indiH1U-tDwquw4tU_UXoQ_sj8OBo8XBUuWjuuFShqmLMP-0W59Vr6CaXdLrF8M3wFR4dUUhSf5UC4QCLaOMVP92lyh0OdtF_m_9Dt7lz-Wniod9zDrHeDsz_by570K3jL1VuDKTl_U1cJ0mzz_zDHGfOUf7VU1kVIs1WnM9SGvnm8YZURLTtMLMWx8-doGUE56Af_VfKjGDYW361OOIj9GmkyCFtaoCmTMIr5kgyeUSnB-IEhDlzujVrV6O9Mt7N4DagR6RGhT3g1viYLS4kO5YindU6dm3GIof1Q",
"results": [
{
"geometry": {
"location": {
"lat": -33.867217,
"lng": 151.195939
}
},
"icon": "http://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
"id": "7eaf747a3f6dc078868cd65efc8d3bc62fff77d7",
"name": "Biaggio Cafe - Pyrmont",
"opening_hours": {
"open_now": true
},
"photos": [
{
"height": 600,
"html_attributions": [],
"photo_reference": "CnRnAAAAmWmj0BqA0Jorm1_vjAvx1n6c7ZNBxyY-U9x99-oNyOxvMjDlo2npJzyIq7c3EK1YyoNXdMFDcRPzwLJtBzXAwCUFDGo_RtLRGBPJTA2CoerPdC5yvT2SjfDwH4bFf5MrznB0_YWa4Y2Qo7ABtAxgeBIQv46sGBwVNJQDI36Wd3PFYBoUTlVXa0wn-zRITjGp0zLEBh8oIBE",
"width": 900
}
],
"place_id": "ChIJIfBAsjeuEmsRdgu9Pl1Ps48",
"scope": "GOOGLE",
"price_level": 1,
"rating": 3.4,
"reference": "CoQBeAAAAGu0wNJjuZ40DMrRe3mpn7fhlfIK1mf_ce5hgkhfM79u-lqy0G2mnmcueTq2JGWu9wsgS1ctZDHTY_pcqFFJyQNV2P-kdhoRIeYRHeDfbWtIwr3RgFf2zzFBXHgNjSq-PSzX_OU6OT2_3dzdhhpV-bPezomtrarW4DsGl9uh773yEhDJT6R3V8Fyvl_xeE761DTCGhT1jJ3floFI5_c-bHgGLVwH1g-cbQ",
"types": [
"cafe",
"bar",
"restaurant",
"food",
"establishment"
],
"vicinity": "48 Pirrama Rd, Pyrmont"
},
{
"geometry": {
"location": {
"lat": -33.866786,
"lng": 151.195633
}
},
"icon": "http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png",
"id": "3ef986cd56bb3408bc1cf394f3dad9657c1d30f6",
"name": "Doltone House",
"photos": [
{
"height": 1260,
"html_attributions": [
"From a Google User"
],
"photo_reference": "CnRwAAAAeM-aLqAm573T44qnNe8bGMkr_BOh1MOVQaA9CCggqtTwuGD1rjsviMyueX_G4-mabgH41Vpr8L27sh-VfZZ8TNCI4FyBiGk0P4fPxjb5Z1LrBZScYzM1glRxR-YjeHd2PWVEqB9cKZB349QqQveJLRIQYKq2PNlOM0toJocR5b_oYRoUYIipdBjMfdUyJN4MZUmhCsTMQwg",
"width": 1890
}
],
"place_id": "ChIJ5xQ7szeuEmsRs6Kj7YFZE9k",
"scope": "GOOGLE",
"reference": "CnRvAAAA22k1PAGyDxAgHZk6ErHh_h_mLUK_8XNFLvixPJHXRbCzg-gw1ZxdqUwA_8EseDuEZKolBs82orIQH4m6-afDZV9VcpggokHD9x7HdMi9TnJDmGb9Bdh8f-Od4DK0fASNBL7Me3CsAWkUMWhlNQNYExIQ05W7VbxDTQe2Kh9TiL840hoUZfiO0q2HgDHSUyRdvTQx5Rs2SBU",
"types": [
"food",
"establishment"
],
"vicinity": "48 Pirrama Rd, Pyrmont"
},
{
"aspects": [
{
"rating": 23,
"type": "overall"
}
],
"status": "OK"
}
]
}
我建议使用像json2csharp这样的网站从该响应中创建C#类,并根据需要操作数据。