[Solved] C# get Image Url from JSON response [duplicate]


You can use LINQ to JSON in Newtonsoft.Json to get url from JSON.

 string stringJson = @"{
            ""total_items"": ""24"",
            ""page_number"": ""1"",
            ""page_size"": ""10"",
            ""page_count"": ""3"",
            ""cars"": {
            ""car"": [
              {
                ""url"": ""<honda-1-url>"",
                ""id"": ""honda-1"",
                ""city_name"": ""Seattle"",
                ""description"": ""black Honda"",
                ""image"": {
                    ""thumb"": {
                        ""width"": ""32"",
                        ""url"": ""<image_url>/honda1.jpg"", 
                        ""height"": ""32""
                                }
                            },
                ""date"": ""2015-12-09 13:20:20""
               },
               {
                    ""url"": ""<honda-2-url>"",
                    ""id"": ""honda-2"",
                    ""city_name"": ""Blaine"",
                    ""description"": ""red Honda"",
                    ""image"": {
                        ""thumb"": {
                        ""width"": ""32"",
                        ""url"": ""<image_url>/honda2.jpg"",
                        ""height"": ""32""
                                    }
                                },
                    ""date"": ""2015-12-09 13:20:20""
                }
                        ]
        }}";

        dynamic dynamicCars = JsonConvert.DeserializeObject(stringJson);

        foreach (dynamic car in dynamicCars.cars.car)
        {
            string url = car.image.thumb.url;
        }

7

solved C# get Image Url from JSON response [duplicate]