Pepa Zapletal
Pepa Zapletal

Reputation: 2979

Windows Phone Deserialize to List JSON .NET

I have problem deserialize string with JSON.Net on WP7. I have this JSON string:

JSON Example

and I have generate from it a class ( http://json2csharp.com/ ).

       void GETHotels()
        {
            WebClient c = new WebClient();
            c.DownloadStringAsync(new Uri(@"..."));
            c.DownloadStringCompleted += new DownloadStringCompletedEventHandler(DownloadStringCompleted);
        }

        DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
        {         
            var deserialized = JsonConvert.DeserializeObject<List<Classes.RootObject>>(e.Result);
        }

But when I try deserialize e.Result, I get Exception:

Error converting value "[{"hotId": ... 6390285}]" to type 'System.Collections.Generic.List`1[Hotel_cz.Classes.RootObject]'. Path '', line 1, position 971.

Can someone help me with this problem?

Upvotes: 1

Views: 1674

Answers (1)

I4V
I4V

Reputation: 35363

This should work...

var hotels = JsonConvert.DeserializeObject<List<Hotel>>(e.Result);

public class Hotel
{
    public int hotId;
    public string Name;
    public double latitude;
    public double longitude;
}

Upvotes: 1

Related Questions