Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/307.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何用c解析嵌套的JSON_C#_Json - Fatal编程技术网

C# 如何用c解析嵌套的JSON

C# 如何用c解析嵌套的JSON,c#,json,C#,Json,下面是JSON的布局 { "Key": "Standard Input", "Value": [ { "code": "2102012000", "attributes": { "Tier 3 Description": "Liquid Waste", "Activity Value Required?": "No", "

下面是JSON的布局

{
    "Key": "Standard Input",
    "Value": [
        {
            "code": "2102012000",
            "attributes": {
                "Tier 3 Description": "Liquid Waste",
                "Activity Value Required?": "No",
                "Tier 3 Code": "02",
                "Sector": "Fuel Comb - Industrial Boilers, ICEs - Other",
                "Tier 2 Code": "04",
                "SCC Level Four": "Total",
                "Tier 1 Description": "Fuel Comb. Industrial",
                "SCC Level One": "Stationary Source Fuel Combustion",
                "Status": "Active",
                "Tier 2 Description": "Other",
                "Data Category": "Nonpoint",
                "Last Updated Date": "3/14/2012",
                "SCC Level Two": "Industrial",
                "Tier 1 Code": "02",
                "SCC Level Three": "Waste oil"
            }
        },
        {
            "code": "2260001000",
            "attributes": {
                "Tier 3 Description": "Recreational",
                "Activity Value Required?": "No",
                "Sector": "Mobile - Non-Road Equipment - Gasoline",
                "SCC Level Four": "Total",
                "Tier 1 Description": "Off-Highway",
                "SCC Level One": "Mobile Sources",
                "Status": "Retired",
                "Tier 2 Description": "Non-Road Gasoline",
                "Data Category": "Nonroad",
                "Last Updated Date": "3/14/2012",
                "SCC Level Two": "Off-highway Vehicle Gasoline, 2-Stroke",
                "SCC Level Three": "Recreational Equipment",
                "Last Inventory Year": "2005"
            }
        },
        {
            "code": "2260002000",
            "attributes": {
                "Tier 3 Description": "Construction",
                "Status": "Active",
                "Activity Value Required?": "No",
                "Tier 2 Description": "Non-Road Gasoline",
                "Sector": "Mobile - Non-Road Equipment - Gasoline",
                "Data Category": "Nonroad",
                "Last Updated Date": "3/14/2012",
                "SCC Level Two": "Off-highway Vehicle Gasoline, 2-Stroke",
                "SCC Level Four": "Total",
                "Tier 1 Description": "Off-Highway",
                "SCC Level Three": "Construction and Mining Equipment",
                "SCC Level One": "Mobile Sources"
            }
        }
    ]
}
这是我控制器中的代码

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.ContentType = "application/json; charset=utf-8";

WebResponse response = request.GetResponse();

using (Stream responseStream = response.GetResponseStream())
{
    StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);

    string text = reader.ReadToEnd();

    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
    javaScriptSerializer.MaxJsonLength = Int32.MaxValue;
    List<EpaSccCodeModel> listEpaSccCodes  = (List<EpaSccCodeModel>)javaScriptSerializer.Deserialize(text, typeof(List<EpaSccCodeModel>));
属性模型

public class EpaAttributeModel
{
    [JsonProperty("Activity Value Required?")]
    public string ActivityValueRequired { get; set; }

    [JsonProperty("Data Category")]
    public string DataCategory { get; set; }

    [JsonProperty("ert valid")]
    public string ErtValid { get; set; }

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

    [JsonProperty("last inventory year")]
    public string LastInventoryYear { get; set; }

    [JsonProperty("last updated date")]
    public string LastUpdatedDate { get; set; }

    [JsonProperty("map to")]
    public string MapTo { get; set; }

    [JsonProperty("option group")]
    public string OptionGroup { get; set; }

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

    [JsonProperty("scc level four")]
    public string SccLevelFour { get; set; }

    [JsonProperty("scc level one")]
    public string SccLevelOne { get; set; }

    [JsonProperty("scc level three")]
    public string SccLevelThree { get; set; }

    [JsonProperty("scc level two")]
    public string SccLevelTwo { get; set; }

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

    [JsonProperty("short name")]
    public string ShortName { get; set; }

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

    [JsonProperty("tier 1 code")]
    public string Tier1Code { get; set; }

    [JsonProperty("tier 1 description")]
    public string Tier1Description { get; set; }

    [JsonProperty("tier 2 code")]
    public string Tier2Code { get; set; }

    [JsonProperty("tier 2 description")]
    public string Tier2Description { get; set; }

    [JsonProperty("tier 3 code")]
    public string Tier3Code { get; set; }

    [JsonProperty("tier 3 description")]
    public string Tier3Description { get; set; }

    [JsonProperty("usage notes")]
    public string UsageNotes { get; set; }
}
返回json数据后,我可以看到代码字段,但属性模型为null


有人能告诉我如何获取json属性部分的值吗?

你能有一个如下的根对象类吗

public class RootObject
{
    [JsonProperty("Key")]
    public string key {get;set;}

    [JsonProperty("Value")]   
    public List<EpaSccCodeModel> Value {get;set;}
}

希望这有帮助

你的问题是什么?请回顾一下,我认为公共EpaAttributeModel AttributeModel{get;set;}与属性不匹配,请尝试向其中添加[JsonPropertyattributes]。我进行了编辑并将问题放入,我正在尝试找出如何获取属性,它返回空值。emed,我尝试了[JsonPropertyattributes]仍然不起作用。我尝试了它,我发现以下错误:数组的反序列化不支持类型“SCCCodes.Models.RootObject”。是否可以使用尝试的控制器代码更新此注释部分?var serial=new System.Web.Script.Serialization.JavaScriptSerializer;serial.MaxJsonLength=Int32.MaxValue;var dict=serial.Deserializetext;公共类根对象{[JsonPropertyKey]公共字符串键{get;set;}[JsonPropertyValue]公共列表值{get;set;}
public class RootObject
{
    [JsonProperty("Key")]
    public string key {get;set;}

    [JsonProperty("Value")]   
    public List<EpaSccCodeModel> Value {get;set;}
}
var rootbject = (RootObject)javaScriptSerializer.Deserialize(text, typeof(RootObject));