Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# deserialization of JSON

I have this JSON string:

{"natalia1891":{"idUser":1435105,"nick":"natalia1891","sefNick":"natalia1891","status":1,"photo":"http:\/\/213.215.107.125\/fotky\/143\/51\/s_1435105.jpg?v=3","sex":2,"isFriend":1},

"pepina888":{"idUser":3338870,"nick":"pepina888","sefNick":"pepina888","status":1,"photo":"http:\/\/213.215.107.127\/fotky\/333\/88\/s_3338870.jpg?v=9","sex":2,"isFriend":1}}

I would like to deserialize this JSON into a dictionary of object Friend. Any advice?

maybe:

class Friend{

public string Name{get;set;}

public string IdUser{get;set;}

public string SefNick{get;set;}

public bool Status{get;set;}

public string Url{get;set;}

public int Sex{get;set;}

public bool isFriend{get;set;}
}
like image 380
Tom Avatar asked Nov 30 '25 17:11

Tom


2 Answers

Use JSON.Net.

like image 185
James Sumners Avatar answered Dec 03 '25 09:12

James Sumners


Have a look at the Json.NET documentation on serializing/deserializing.

You may need to do a little work to effectively make it case-insensitive, although it looks like James made it fairly forgiving a while ago.

like image 38
Jon Skeet Avatar answered Dec 03 '25 09:12

Jon Skeet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!