C#JavaScriptSerializer.Deserialize返回null

问题描述 投票:0回答:1

正在努力反序列化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; }
    }

努力反序列化JSON字符串,我只是从序列化程序返回null。 JSON有效,已检查。我的眼睛因盯着这个而for目结舌,所以现在登录,所以...

c# json-deserialization javascriptserializer
1个回答
0
投票
public partial class RootObject
{
    [JsonProperty("Tags")]
    public List<Tag> Tags { get; set; }

    [JsonProperty("Data")]
    public List<Datum> Data { get; set; }

    [JsonProperty("OutParameters")]
    public List<OutParameter> OutParameters { get; set; }
}

public partial class Datum
{
    [JsonProperty("LogonName")]
    public string LogonName { get; set; }

    [JsonProperty("NetBiosName")]
    public string NetBiosName { get; set; }

    [JsonProperty("FriendlyName")]
    public string FriendlyName { get; set; }

    [JsonProperty("Description")]
    public string Description { get; set; }

    [JsonProperty("GroupTypeName")]
    public string GroupTypeName { get; set; }

    [JsonProperty("AllowJoinRequests")]
    public bool AllowJoinRequests { get; set; }

    [JsonProperty("RiskFactorTotal")]
    public object RiskFactorTotal { get; set; }

    [JsonProperty("IsHighSecurityGroup")]
    public bool IsHighSecurityGroup { get; set; }

    [JsonProperty("Email")]
    public object Email { get; set; }

    [JsonProperty("DistinguishedName")]
    public string DistinguishedName { get; set; }

    [JsonProperty("ResourceID")]
    public long ResourceId { get; set; }

    [JsonProperty("GroupID")]
    public long GroupId { get; set; }

    [JsonProperty("ValidUntil")]
    public object ValidUntil { get; set; }

    [JsonProperty("IsMailEnabled")]
    public bool IsMailEnabled { get; set; }

    [JsonProperty("Notes")]
    public object Notes { get; set; }

    [JsonProperty("RiskFactorLastCalculated")]
    public object RiskFactorLastCalculated { get; set; }
}

public partial class OutParameter
{
    [JsonProperty("Name")]
    public string Name { get; set; }

    [JsonProperty("Value")]
    public long Value { get; set; }
}

public partial class Tag
{
    [JsonProperty("Name")]
    public string Name { get; set; }

    [JsonProperty("TotalOccurrences")]
    public long TotalOccurrences { get; set; }

    [JsonProperty("SizePercentage")]
    public double SizePercentage { get; set; }
}
© www.soinside.com 2019 - 2024. All rights reserved.