0

I have a JSON String returned by Google Places API which somewhat looks like this:

{ "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" 

I want to convert this JSON string into more usable type ideally like string[]. I tried

 var serializer = new JavaScriptSerializer();
 string[] arr = serializer.Deserialize(result,string[]);

But I am aunable to get the second argument to Deserialize right. Please help me out with this.

1
  • Instead of string[] try typeof(string[]) as the second argument. Commented Jul 11, 2014 at 21:00

1 Answer 1

0

Edit:

Your JSON is in the wrong format. If you're using the demo response to test, it's not formatted properly.

Here is a modified version in the correct format

{
    "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"
        }
    ]
}    

What I'd suggest, is using a website like json2csharp to create C# classes from that response, and manipulate the data as needed.

Sign up to request clarification or add additional context in comments.

4 Comments

this return an empty array.
please update the JSON string in your OP. It appears that not all of it is included. Also, this doesn't appear to be a true string array. You might need to deserialize it to an object, and then take the data you want from it. This JSON appears to have multiple levels, therefore won't deserialize into a simple string[]
you can view the returned Google Pleaces API JSON here
Please see my edit. You will need more than just a string array to handle this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.