tags:

views:

35

answers:

2

I get this JSON resposne from a server:

{"User1":0, "User2":0,"User3":0,"User4":0,"User5":0,"UserN":0,}

Users can be from 0 to N.

I want to deserialize this JSON string into a List of Users

public class User
{
 public string Name{get;set;}
 public string Status{get;set;}
}

I try this but it doesn't work.

List<Users> peoples;

peoples = new JavaScriptSerializer().Deserialize<List<Users>>(jsonString);
A: 

Hi,

Can you try this?

JavaScriptSerializer mySerialiser = new JavaScriptSerializer(new SimpleTypeResolver());

Kind Regards,

Edit:

In your case:

peoples = new JavaScriptSerializer(new SimpleTypeResolver()).Deserialize<List<Users>>(jsonString);
Trefex
Hi Trefex, i try your advance, but it doesn't work.It finish with this errorCannot convert object of type 'System.Boolean' to : type 'System.Collections.Generic.List`
Tom159
Use this syntax also to serialize the object.
Trefex
+2  A: 

The reason this is not working is because the JSON string you are receiving is not a list of objects but a single object with multiple properties. A list is usually represented with [] in JSON:

[{"Name":"User0","Status":"0"},{"Name":"User1","Status":"0"}]
Darin Dimitrov
but, i get from server only JSON string...
Tom159