如何从任务<string>解析JSON

时间:2015-09-26 17:31:35

标签: c# json parsing

我尝试用C#解析Json数据,但我不知道如何从Task函数解析它。

这是我从Google地图获取Json数据的代码

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace PhoneApp3
{
    class getJson
    {
        public getJson()
        {

        }

        public async Task<string> RequestJsonFromGoogleMap(double lat, double lng)
        {
            //JSON String var
            string returnString = "";

            // server to POST to
            string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location="
                         + lat
                         + ","
                         + lng
                         + "&radius=500&types=food&name=cafe&key=AIzaSyAOi7TswVYRlkqvZcQ88Qf9SUHODK67TR0";

            // HTTP web request
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

            using (var response = (HttpWebResponse)(await Task<WebResponse>.Factory.FromAsync(request.BeginGetResponse, request.EndGetResponse, null)))
            {
                using (var responseStream = response.GetResponseStream())
                {
                    using (var sr = new StreamReader(responseStream))
                    {

                        returnString = await sr.ReadToEndAsync();
                    }
                }
            }
            return returnString;
        }
    }
}

如果我运行代码

RequestJsonFromGoogleMap(21.0277644, 105.8341598);

我将按照以下方式获得String Json 那么如何获取每个位置的坐标?

{
   "html_attributions" : [
      "Danh sách của \u003ca href=\"http://www.diadiem.com/\"\u003eDiadiem.com\u003c/a\u003e"
   ],
   "results" : [
      {
         "geometry" : {
            "location" : {
               "lat" : 21.02801,
               "lng" : 105.833981
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "dbe7241ce0a344b5abbdb4739fc6d7418c4b3436",
         "name" : "Quán Cafe Like HD",
         "place_id" : "ChIJbWYHx56rNTERP6vYPIhoQAA",
         "reference" : "CnRkAAAATz9LRM-T9Wg7b7XL7O51bcVMJ29j0wltu5vw9dcLJ2oeI7zVvJ5saniSDiY-pjugCgc7cZt4hQ41fKLeOigxx_gAFrPdFksJE1STlw0AOGzPZEtboYc1iR7lC7DP94-5fMQmQBwmZyIaj3UCdWFnihIQQdj32THijNT7HVGVjAyAHxoUDjRBdQKu2hmaGV9GtXXFyCurmQU",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "5, Ngõ 35, Cát Linh, Quận Đống Đa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.026267,
               "lng" : 105.833024
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "71e82d31410bee47a695df51dcc61cc3e09b21f0",
         "name" : "Quán Cafe Hoa Sữa",
         "place_id" : "ChIJgZHPJpyrNTERHtMgJbtksW8",
         "reference" : "CnRnAAAAEPGMAN40IRWd5BnbPwJg76HdNC16Gm91r-Q_RRbJUZ6nXX-dYa0udcjK8QKBuaI0VFRXJnJ7RRYNVI1T4g5XcG8d7R-bBIV0nXQpmZTPxq85b2irEVEb_e21A_BZ6bgVDJcUAmyhx-4CSvfB8rWbthIQcXh0DX-7Z0ybfqf6HS82hxoUOf72mW2rphi7avaX2a1FQhCR4mk",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "9, Đoàn Thị Điểm, Quận Đống Đa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.029604,
               "lng" : 105.835101
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "94ead5be053ed60c342f69f45a33a7758f29a67b",
         "name" : "Quán Hiền Cafe",
         "place_id" : "ChIJJT-D05irNTERQFwmXZAymfw",
         "reference" : "CnRlAAAAkDUh4RiMruJWIAx9NZzBRjgB-yCyNWLNUby0q1jtbTxmUExM__f4uZciPFAhIxmuF_No6biioxfGGQl0prlPMOQDrh_lBKPkYPKW21rocPtMTEbr75D0mXxIu95d4jB2i9y0eK6LmyZBDOqctTqwShIQb-BotKJ8BnVme4URj1rxwhoUvNT6tAHPLbGhU6moBLwc_XuVlcg",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "29, Ngõ Hàng Cháo, Quận Đống Đa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.026272,
               "lng" : 105.832174
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "7a09e156801f4e0e114582a82a6d8608d8f21188",
         "name" : "Cafe Rosy",
         "place_id" : "ChIJtdS8K5yrNTERqMgDVazC758",
         "reference" : "CmRdAAAARKuWVgiKkq-6tptuiDQlqFfU4VTBY7uQm8ex8aKmPWSIRda2LiT5uuT_NmAiFQeDPGQ5N9-4l175q7ci9d1pqVsI8y-rBHusyLYlvRFcgvtfYpdQugYxLfuUmRbf_CzgEhDqYmmgLTL6Qan0Eynxha5TGhQcrqEG3Zj0QYr5HU3BSTFYO0cxsA",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "so nha 33, Đoàn Thị Điểm, Quốc Tử Giám"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.027791,
               "lng" : 105.837255
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "b7498aa5dd32182740ba0ec0a69e937a62301087",
         "name" : "Quán Cafe Trường Xuân",
         "place_id" : "ChIJFT2xDZmrNTERQALEmVOBiXs",
         "reference" : "CnRtAAAAVP5cp2TqkpENlc9O3gsj7_NRNAk3rRW36aZSv2fNssRGSX4E3nDbJmt_TJ3ihmuwXMjEnk0aE4vKIlxJJRXy_-eX7bjY2xXFcfhL1fxgM9VhYmT2_STo_I3CPV8Yt33Fwz6W_8ld8svH3SVgBvjJRxIQRR1Iyg58tNy74a8z5d4VDBoU-DpF9GzXoQqkjU2njV5A9Abmc9I",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "13, Ngô Tất Tố, Quận Đống Đa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.024527,
               "lng" : 105.834137
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "d5b9f11ea52fc10f07082b9225539767cac2c715",
         "name" : "Smile - D 3D Film Cafe",
         "place_id" : "ChIJ6QkbbpyrNTERNvNgDbQSmcE",
         "reference" : "CnRqAAAAkP6dq9nw_T3o5T3h0dxCpujo5h4TB4TTCy4_YaBRV45ZH8Df6s05qwvTQcn-6g-v_JpDuqHPaysAYtDB7oGU3aebCxjHcj6fsLKg31EUhgyy3Nk2GEce-Bx6kev-I-Tdd67eUp4ToNuNLb39WtX5NhIQT_nKEYFdI5uzjNLD4449rhoU275MY8jYoOScjxy-JvztHlVMSL4",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "106D1, Van Chuong Street, Dong Da District, Ha Noi City"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.032016,
               "lng" : 105.831749
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "fa93189cacb177745282f97bf85ffa4adda0d67c",
         "name" : "Cafe nguyễn thái học",
         "place_id" : "ChIJW7bRg5-rNTERfTypANbuum4",
         "reference" : "CnRsAAAAGBAfGu2HFdTVSUk9OO4vvnclFrVelDmIUfX9XKk3aQWwy_8Ko4YYDA85usUEftxJ8WKFPsHkTki0vxLFxN_ojrPRMxnx9ENMn9yBvngrBu8idrFoHjbd8oGW_1ALwB6-nr6_rRbEPTZ6Y5HLYA_T7BIQsfNFJXM5YqBkrLr00nrA_BoUZ4_DcOonC-hF4OAPsqv47n3X2rI",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Phố Thanh Báo"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.029862,
               "lng" : 105.837125
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "7fa0f81dbab48e814f0b370c02c0c22f6b93e270",
         "name" : "Cafe Bất Động Sản Hà Nội",
         "photos" : [
            {
               "height" : 407,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/101531822538452839905\"\u003exuân kiên nguyễn\u003c/a\u003e"
               ],
               "photo_reference" : "CmRdAAAAwr28gHaD1gjfTmB_Tpa6MviHOAt9UaqzWD6BbfRy_2kcz5Xqq2UOxQdUqSMektZKi51lOvH-AWQhJ3ZkHhtbRfYMXe3N__lyvPIQWl6ixJyd8EBN1uRJC6KYqsSh2U63EhDwe-1zOoiKQNn39Sxs_iT2GhQywTJaFBqnYn1Bltr6LwZnqoR4yA",
               "width" : 613
            }
         ],
         "place_id" : "ChIJ73Qm8JirNTERGaUq15p9skY",
         "reference" : "CoQBdQAAAG7uXqmLZddaFv9zDwokNts5dG7Ip48A1NCiisR_dNeIm26S3hMJk94xpqqQ-uK4zsVH7VPsy53MCwNg1H1dHN2zA_3WBUPKSVXQdKjRey74VHAzM-ciSlEfRL3lLo4RtUDs_-7lZJacS9bFAaSW46S8dmYk8A49UbDEjM2vMLpeEhCdy9z7xwTvu6EcOpaq_ScZGhRApEpQ5FBp59q9MYhbKrWMkTBlFA",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Thanh Miến, Điện Biên"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.031892,
               "lng" : 105.8371
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "1f17e174c5273cc7f7029ffc9ee9194c0aa00d18",
         "name" : "Cà phê Chim Xanh",
         "place_id" : "ChIJO-vhd6KrNTERfBng4Um1mZo",
         "reference" : "CnRmAAAA-HbWbbxD-zaJsJKsVdJ1_E2w0Pb8KhqXr_gUUTpGY6NEakgPr0nLzJnEXQgLS2nqhd1X2xYguPlLjz7uyICXM15oHmKML5Ln_PVd_Ah92xXjX7Sct46OgLx0zXD2huNDBLebTn41_DWzJcwLrckWbBIQwSs3BLfb2I6vg5vast5YYxoUnWuhwoQSfua9cnrX1_vqUCxh2PY",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Quan Ba Dinh"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.032108,
               "lng" : 105.837075
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "d04bc1a0e8a142729b10e6084c63ba104602f3c7",
         "name" : "Like Cafe",
         "place_id" : "ChIJSz95d6KrNTER8mCj0wFvfXQ",
         "reference" : "CmRcAAAARWNxvO5uL6a5sWxGqeD6IZGyLCPpipDTJ8B2eNalzt1LNX5ePijrjdjClgyUSEDKixLWJr4nUJrNKZaIeKX2L3mFHS6ZLxJzBYu4CyF2SN5Ftb2xiL8MyFmdj7uohrB7EhDFBKMTGYe066z_zRMr83JEGhQmgQ3t8l1lbrwDzsXs1ySQVFgjPQ",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Quan Ba Dinh"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.023894,
               "lng" : 105.830579
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "f0894ec94096a1ee87673bb08d75edd994b766ec",
         "name" : "Catchy Cafe",
         "place_id" : "ChIJTwYToJ2rNTER5wZCThkXUbs",
         "reference" : "CmRfAAAAviDXkuBJ794SlMMw4ji5SZ4YZgQ4_ma3QzaJWYNYYH3yg4kL7FBQiIubRyGcfDnPTYRL3penHeRo-Xf3ekf_uiw_vlIkKI4F6O9_DeSKVnGYr1ao7uzqvNoPIUfS7ZpyEhBJq2Max4XNkEaXWwH529rVGhRDdgmX03JmWyYfKis0xpgCGjdxhg",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "Ngõ Thịnh Hào 1, Hàng Bột"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.032223,
               "lng" : 105.837106
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "7d8153b6cedba1646c354e57ddde11e1d2630f07",
         "name" : "Tầng Trệt Cosmo Café",
         "opening_hours" : {
            "open_now" : false,
            "weekday_text" : []
         },
         "place_id" : "ChIJ9bHieaKrNTERL5fdK05fT-g",
         "reference" : "CnRtAAAA-fsbjm9lz6wEZlG4yWYjmdIBlhhZp_4JNj7ElWmsVeij97YxN8snZQLtrAuaKn5OIGTDBGm7VLqeOQRlnGg-XuG8eRl9McqFCA6GK3nf6yc9kWSazGEy-14kFP3UIPGbPaX0DX_8GGL1N0bgqZBQYBIQ75mynmp7aDZMu2YoK0cwMxoUnCWmaFzNzaNCuupzjzYXgBVMqGg",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "10, Khúc Hạo, Điện Biên"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.025721,
               "lng" : 105.827622
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "168fde0a918fd47519d82fd1a248f1726b89a485",
         "name" : "Cafe 156 Hào nam",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 371,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/102467009897419812035\"\u003eCafe 156 Hào nam\u003c/a\u003e"
               ],
               "photo_reference" : "CmRdAAAAHm4yAQiqqlwcw1pN2dSxHK2F1HeoDT0DudHfM7OAts6iB1eYvL_5qsLR70M2e8XlfkuwfXZiPZEIKCWgA0VL8QwWzJj6Vm8zOl2FeSH2nRJdVABijSHWE_ZwJmvJ22MeEhCLAww0xwdJzmzGoQHIR5HVGhTtqp7kLer2-NPLjC22dLJeQ7N1mw",
               "width" : 371
            }
         ],
         "place_id" : "ChIJ1dYoFXarNTERWFUFuK3wlW8",
         "reference" : "CnRkAAAAZcsc2rVZ_gDW6qXYIdSeFVQPJteYW8RfPZWFzXIrVDhN4Tbjx1Z9u0sptL97azDDGBkaS-hMUy8rmjXrVYWpbrP7qkDJpFvbSlUjMcP1RSRASi6QPIqo7Wc9mys2DgZQ0RaWiX8scmQXDYfQCAKEQRIQv4eLUFbP-_sge9nCMdb2ABoU9b1riIHf65YuQtg-JW-G_tNQYCg",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "156 Hào Nam, Ô Chợ Dừa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.021991,
               "lng" : 105.832687
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "c6233ec0d0130a2b72a60bb1b2c95ed6e4660eca",
         "name" : "Quán Cafe Đạt",
         "place_id" : "ChIJw1fU3JyrNTERPhaLD4nbgNQ",
         "reference" : "CnRlAAAA08OwnSM4Ihq_cDsyB6aFoPYCy1CkcEfuI769BjxGi-LI2GUsSYGFTx7kz2P2agD48quAfNM6SiYQMQlMbY9ASENSYslkuFm1aHsj-V6vxof0XWlBrH3KuLRaDhOZPNFUS6OuGb0xYNlXYVSpg7Z4CxIQ7nWYAbptq-kHr0Ew8VkiYRoUQHBltdpJ-bWG9dt-GNlP5ntfgLI",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "6, Hồ Văn Chương, Quận Đống Đa"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.032126,
               "lng" : 105.840075
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "ed4843c8857ca0738d3467f88b34fc1306f0c02e",
         "name" : "Cafe Highlands",
         "photos" : [
            {
               "height" : 1200,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/104875905065716317600\"\u003eBas van Haarlem\u003c/a\u003e"
               ],
               "photo_reference" : "CmRdAAAAJEYCTZWQRN9gXr_2UdpSGbKV_sof6d0JA6qMNRblQwJJ5gRwKPIlqmyi0linDOXtnbDBygARv2lrmw1X6SKpeggUWqPIdu60csYct8vyoAU4iGbEbM-LNl7oamFa6j4hEhC4bfBlfd9siFZLfdHtXxIwGhSACjqhIicDVSNJNOXxZvR9LMPi1g",
               "width" : 1600
            }
         ],
         "place_id" : "ChIJr9F6r6KrNTERvQdNtiqADAU",
         "reference" : "CnRhAAAAGnvHn78FcEmH32-weP9_S22dy0sGjRD_CGfrhCyC4CHtiM6t2R8N4xXfUEEaFd-Ji2WdP7kqm4DubddUsZMCk9A9NAFLpWgMgqUJmShR6B--bwjEAUYaJBlD7IYnDkYWeFKFyStbyqbJ-7m4-nFArRIQfdDr9wfbhxku-p4FnrLssxoUkkJk0pRgQ2p5dVO0CWg-v_LxDw0",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "28A, Điện Biên Phủ, Phường Điện Biên, Quận Ba Đình, TP Hà Nội"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.025799,
               "lng" : 105.827633
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "018e4bd5c89647cae776466427ee27ab4d1e5ed2",
         "name" : "Cafe Luna, 158 Hào Nam",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "place_id" : "ChIJ63vDFHarNTERZVeqPerUMf4",
         "reference" : "CnRrAAAABxc3M3uVryAZ8hizBwDLqc7XQh-0BRNRBu2E5lCXV3ciSjYs-nXectvyaCszBVO_ypMA5pJRIympbCvbKCjvbDcarxhMx0N8jhB8W48X0ChjF1HLUkjwiz9bPTfXFLIBNXVr7Xq96teWhMR1qW6hpBIQedbdlB5uNuqkgDDr6p1iBxoUv9Pzc2K5wAsh-Nmgip6C_cXLRO8",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "158 Hào Nam Ô Chợ Dừa Đống Đa Ô Chợ Dừa Đống Đa Hà Nội Vietnam"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.027981,
               "lng" : 105.836309
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "dc3decfeaaf18d0cc130f609401cefe162ca25c3",
         "name" : "Cafe Trang",
         "opening_hours" : {
            "open_now" : true,
            "weekday_text" : []
         },
         "photos" : [
            {
               "height" : 612,
               "html_attributions" : [
                  "\u003ca href=\"https://maps.google.com/maps/contrib/112246688549713635014\"\u003ePhilip Swan\u003c/a\u003e"
               ],
               "photo_reference" : "CmRdAAAAdqd8YLKN6iA6UWScmW7PlRY2Gnh-zA7yyfoLjhalhwfNJqtZVT5oABHfKw3U-KwTEDZSN3dbnPEzwjDkX9kWeowo5T60cagZufW5DxSv7F9vCEal0HcysdzUfIsQXLWJEhBj-7aZvZzST-T6P8ggiT_NGhSWGHF4Lb6KCLYobVeYSWcRXnk7Jg",
               "width" : 816
            }
         ],
         "place_id" : "ChIJResNPpmrNTER6G9KodUxB_4",
         "reference" : "CmReAAAAo9a55sq3m2dwRN-RASBNPiZbT4tgWfpKCu_U0WcqlzaSi5Qh7OpUN7UkMy692J86aVQJjk-jCEatrbXdLNdkJHmD3eHmpQMWa9CbwJW2B4WcXdW5t8WXqVHMrr6CQ_MbEhCNrpdIeDOZOHG1a3oWPxoFGhReQVLyB9iqakfE6t1568fDNrdCCQ",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "House, 47 Văn Miếu, Quan Dong Da"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.030934,
               "lng" : 105.840848
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "9ca61ba806a3a2b04759a8b735dfb4c2b79a9c31",
         "name" : "Cafe - Smoothies",
         "place_id" : "ChIJgb5r-JerNTER-tWRU_JZAk8",
         "reference" : "CnRjAAAAC7PaswMev3bzCgyfVuEqhQFAK8zuQIu5Jd-bWvYIl7Gmtv5r7Zhd7jKeruaLMKtbqVMwI2kbeIt-oDZtfPu2zz713Ev69bBDXFyiAFnDglmsr0riyJMLhPZA0n-yrW4Yq2V32nxSh8oX7ISy3HuMKRIQXTJbn11WFlRLYO4GkecbZhoUc6OqB12Kh0R_oc0ESkGJ9JS7l5k",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "23 Dien Bien Phu Street, Ba Dinh District"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.032746,
               "lng" : 105.829915
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "8aa131411fe5dec96961ad13a9c2a9b4bdb6cae4",
         "name" : "Cafe HN",
         "place_id" : "ChIJ12QEHaCrNTERWeqsw80pP60",
         "reference" : "CmRbAAAAJwWNdCCUuHCGplj1T_1ficAMx6euXQ2Fh1lIv-DTPf1rzw8QUZwrY_PIUETiSAeIx7fA4GZiPghvorxMMT-kjDsRnsQ2PVQRLchFKaoSHEhrd76nCTlyC9thCF3Gpb-NEhBYnWzPIyDQPzd6QRBrQGF8GhRoVZm7__JbrMX2rPzonLzVgh2rOg",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "115 Sơn Tây, Kim Mã"
      },
      {
         "geometry" : {
            "location" : {
               "lat" : 21.033428,
               "lng" : 105.838661
            }
         },
         "icon" : "https://maps.gstatic.com/mapfiles/place_api/icons/cafe-71.png",
         "id" : "feeb7add0c62cba9ad227e57a5e851aae6e9638f",
         "name" : "Dimah Cafe Shop",
         "place_id" : "ChIJh3aY7aKrNTERRSIAd_9VxY0",
         "reference" : "CnRjAAAA1-jYQhJQoqrzOy0zD634gIUc52drimiGQRM4FfFA7JjUpqN7_-472nP0fSe1W9i80DY_RFqaq9ssghB8bAeM0xNaNcT6pgHAcPGBde8r318lSLzM2IzlvQueEiUVkW_4hUI8nkDuGv5RePER4mwWvBIQdCoflzgMjXG2JCjQpZjoXBoU_o8kH-CU9D5q0bCM7h2GqHFy09o",
         "scope" : "GOOGLE",
         "types" : [ "cafe", "food", "point_of_interest", "establishment" ],
         "vicinity" : "32B, Dien Bien Phu Street, Ba Dinh District, Ha Noi City"
      }
   ],
   "status" : "OK"
}

3 个答案:

答案 0 :(得分:1)

string jsonResult = await RequestJsonFromGoogleMap(21.0277644, 105.8341598);

然后将json转换为你需要的东西!

答案 1 :(得分:1)

您可以使用newtonsoft json反序列化器来反序列化字符串: Example

答案 2 :(得分:0)

我创建一个Json类,如下所示:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace PhoneApp4
{
    class JsonSearchNearby
    {
        public class Location
        {
            public double lat { get; set; }
            public double lng { get; set; }
        }

        public class Geometry
        {
            public Location location { get; set; }
        }

        public class OpeningHours
        {
            public bool open_now { get; set; }
            public List<object> weekday_text { get; set; }
        }

        public class Photo
        {
            public int height { get; set; }
            public List<string> html_attributions { get; set; }
            public string photo_reference { get; set; }
            public int width { get; set; }
        }

        public class Result
        {
            public Geometry geometry { get; set; }
            public string icon { get; set; }
            public string id { get; set; }
            public string name { get; set; }
            public OpeningHours opening_hours { get; set; }
            public List<Photo> photos { get; set; }
            public string place_id { get; set; }
            public string reference { get; set; }
            public string scope { get; set; }
            public List<string> types { get; set; }
            public string vicinity { get; set; }
        }

        public class RootObject
        {
            public List<object> html_attributions { get; set; }
            public List<Result> results { get; set; }
            public string status { get; set; }
        }
    }
}

但是,当我转换时,VS响应错误

  
      
  • 'Newtonsoft.Json.JsonConvert.DeserializeObject(string)'的最佳重载方法匹配   有一些无效的论点

  •   
  • 无法从'System.Threading.Tasks.Task'转换为'string'

  •   
  • 字段初始值设定项无法引用非静态字段,方法或属性'PhoneApp4.MainPage.RequestJsonFromGoogleMap(double,   双)'

  •