Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JSON.net stuck at DeserializeObject

Tags:

json

c#

json.net

I've got a JSON as following

{"name1":20,"name2":22}

My aim is to save it in a List of People so that it can be used afterwards, so I first wrote the class People:

class People
    {
        public String name{get;set;}
        public long age{get;set;}
    }

I wrote as long as to prevent this deserializing errors.

Then I wrote the following code:

String json= new System.Net.WebClient().DownloadString(url);
List<People> people= JsonConvert.DeserializeObject<List<People>>(json);

But it gets stuck at processing this last line (no errors / no crash ..), why?

like image 522
zurfyx Avatar asked May 22 '26 05:05

zurfyx


1 Answers

I think your Json should look more like this if you want to deserialize to List

[{"name":"Name1","age":20},{"name":"Name2","age":22}]

like image 179
S. Binder Avatar answered May 24 '26 18:05

S. Binder