我正在尝试去散化json字符串的值,如下所示
{"data":[
{"description":"xxxxxx","created_time":1330356685},
{"description":"zzzz","created_time":1329817903}
]}
我的课如下:
public class NewFriends
{
public Data[] data { get; set; }
public class Data
{
string description { get; set; }
int created_time { get; set; }
}
}
但是当我反序列化值时,我在nFrnds的数组索引中得到了空值
NewFriends nFrnds = serializer.Deserialize<NewFriends>(newFriends);
请帮忙!
最佳答案
这段代码适合我:
string s = "{\"data\":[{\"description\":\"xxxxxx\",\"created_time\":1330356685}, {\"description\":\"zzzz\",\"created_time\":1329817903}]}";
JavaScriptSerializer jss = new JavaScriptSerializer();
NewFriends nFrnds = jss.Deserialize(s, typeof(NewFriends)) as NewFriends;
MessageBox.Show(nFrnds.data.Length.ToString());