【发布时间】:2020-04-21 16:21:08
【问题描述】:
努力反序列化 JSON 字符串,我只是得到 null 从序列化程序返回。
JSON 是有效的,我已经检查过了。
我的眼睛因为盯着这个看,所以现在记录下来,所以希望比我更有序列化器经验的人能发现一些“明显”的东西!?
感谢任何提示:)
RootObject[] jsonResponse = null;
try
{
if (httpWResp.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = httpWResp.GetResponseStream();
string jsonString = null;
using (StreamReader reader = new StreamReader(responseStream))
{
jsonString = reader.ReadToEnd().Replace("\\", "");
reader.Close();
}
JavaScriptSerializer sr = new JavaScriptSerializer();
jsonResponse = sr.Deserialize<RootObject[]>(jsonString);
Json 是这样的:
{
"Tags":[
{
"Name":"Requestable",
"TotalOccurrences":1,
"SizePercentage":0.33333333333333331
},
{"Name":"Generic","TotalOccurrences":1,"SizePercentage":0.33333333333333331},
{"Name":"YYYYYYY","TotalOccurrences":1,"SizePercentage":0.33333333333333331}
],
"Data":[
{
"LogonName":"xxxxxxxxxxxxxx",
"NetBiosName":"YYYYYYY",
"FriendlyName":"xxxxxxxx",
"Description":"xxxxxxxxxx",
"GroupTypeName":"zzzzzzzzz",
"AllowJoinRequests":true,
"RiskFactorTotal":null,
"IsHighSecurityGroup":false,
"Email":null,
"DistinguishedName":"xxx,yyy,xxx",
"ResourceID":12345,
"GroupID":6789,
"ValidUntil":null,
"IsMailEnabled":false,
"Notes":null,
"RiskFactorLastCalculated":null
}
],
"OutParameters":[
{"Name":"totalCount","Value":1}
]
}
我的课是这样的:
public class RootObject { public List<Tag> Tags { get; set; } public List<Datum> Data { get; set; } public List<OutParameter> OutParameters { get; set; } } public class Tag { public string Name { get; set; } public int TotalOccurrences { get; set; } public double SizePercentage { get; set; } } public class Datum { public string LogonName { get; set; } public string NetBiosName { get; set; } public string FriendlyName { get; set; } public string Description { get; set; } public string GroupTypeName { get; set; } public string AllowJoinRequests { get; set; } public string RiskFactorTotal { get; set; } public string IsHighSecurityGroup { get; set; } public string Email { get; set; } public string DistinguishedName { get; set; } public int ResourceID { get; set; } public int GroupID { get; set; } public string ValidUntil { get; set; } public string IsMailEnabled { get; set; } public string Notes { get; set; } public string RiskFactorLastCalculated { get; set; } } public class OutParameter { public string Name { get; set; } public int Value { get; set; } }
【问题讨论】:
标签: c# json-deserialization javascriptserializer