[英]C# deserialization of JSON
I have this JSON string: 我有这个JSON字符串:
{"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}, { “natalia1891”:{ “ID用户所”:1435105, “缺口”: “natalia1891”, “sefNick”: “natalia1891”, “状态”:1, “照片”:“HTTP:\\ / \\ / 213.215.107.125 \\ /壹图LOGO \\ / 143 \\ / 51 \\ /s_1435105.jpg v = 3" , “性别?”: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}} “pepina888”:{ “ID用户所”:3338870, “缺口”: “pepina888”, “sefNick”: “pepina888”, “状态”:1, “照片”:“HTTP:\\ / \\ / 213.215.107.127 \\ /壹图LOGO \\ / 333 \\ / 88 \\ /s_3338870.jpg v = 9" , “性别?”:2 “isFriend”:1}}
I would like to deserialize this JSON into a dictionary of object Friend. 我想将此JSON反序列化为对象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;}
}
使用JSON.Net 。
Have a look at the Json.NET documentation on serializing/deserializing . 查看有关序列化/反序列化的Json.NET 文档 。
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 . 你可能需要做一些工作才能有效地使它不区分大小写,尽管看起来詹姆斯在不久前让它变得相当宽容 。
您可以在.Net框架中使用JsonDataContractSerializer
类 。
Friend[] friends = new JavaScriptSerializer().Deserialize<Friend[]>(myString);
JavaScriptSerializer在System.Web.Script.Serialization中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.