我正试图像这样反序列化json:
{
"version": 3070,
"settings": [
[
"settingInteger",
0,
"1513486800",
{
"param": "A"
}
],
[
"settingBool",
1,
"false",
{
"param": "B"
}
],
[
"settingString",
2,
"somedata",
{
"param" : "C"
}
]
]
}
所以我尝试使用DataContraceJsonSerializer
反序列化到这个类:
[DataContract]
public class SettingSet
{
[DataMember(Name = "version")]
public int Version { get; set; }
[DataMember(Name = "settings)]
public Setting[] Settings { get; set; }
}
[DataContract]
public class Setting
{
[DataMember(Order = 0)]
public string OptionName { get; set; }
[DataMember(Order = 1)]
public SettingType Type { get; set; }
[DataMember(Order = 2)]
public string Value { get; set; }
[DataMember(Order = 3)]
public Dictionary<string, string> Parameters { get; set; }
}
但我只能获得Version
和数组空Settings
如果我使用object[][]
代替Setting[]
,我可以获得一些数据,但param
仍然无法访问。
有没有办法解决这个问题,还是应该使用其他JSON库?
答案 0 :(得分:0)
var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();
SettingSet settingSet = serializer.Deserialize<SettingSet>(jSon);