C# deserialization of JSON
I have this JSON string:
{"natalia189开发者_开发知识库1":{"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;}
}
Use JSON.Net.
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.
You can use the JsonDataContractSerializer
class in the .Net framework.
Friend[] friends = new JavaScriptSerializer().Deserialize<Friend[]>(myString);
JavaScriptSerializer is in System.Web.Script.Serialization.
精彩评论