排列深度嵌套的Json数组windows phone c#

排列深度嵌套的Json数组windows phone c#,c#,json,restsharp,arrays,C#,Json,Restsharp,Arrays,我有以下JSON字符串: { "response": { "hash": "5e042385c8e1d674056e53483828759e", "resp_code": "USER_SESSION_RETRIEVED", "code": 200 }, "structure": { "company": { "company_id": 3, "company_n

我有以下JSON字符串:

{
    "response": {
        "hash": "5e042385c8e1d674056e53483828759e",
        "resp_code": "USER_SESSION_RETRIEVED",
        "code": 200
    },
    "structure": {
        "company": {
            "company_id": 3,
            "company_name": "The Ministry of Vaccines",
            "alarm_cnt": 4,
            "regions": [
                {
                    "sites": [
                        {
                            "assets": [
                                {
                                    "asset_id": 71,
                                    "asset_name": "Unassigned",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 1,
                                    "components": [
                                        {
                                            "latest_reading": "21.6°C",
                                            "component_id": 503,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Ambient",
                                            "latest_reading_tstamp": "2014-09-13 04:00:00"
                                        }
                                    ]
                                },
                                {
                                    "asset_id": 72,
                                    "asset_name": "Pharmacy fridge",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 2,
                                    "components": [
                                        {
                                            "latest_reading": "6.7°C",
                                            "component_id": 499,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Top",
                                            "latest_reading_tstamp": "2014-09-13 04:00:00"
                                        },
                                        {
                                            "latest_reading": "11.5°C",
                                            "component_id": 500,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Bottom",
                                            "latest_reading_tstamp": "2014-09-13 04:00:00"
                                        }
                                    ]
                                }
                            ],
                            "site_id": 35,
                            "site_name": "Acadia Pharmacy"
                        }
                    ],
                    "region_name": "Acadia Pharmacy",
                    "region_id": 25
                },
                {
                    "sites": [
                        {
                            "assets": [
                                {
                                    "asset_id": 73,
                                    "asset_name": "Cold room A",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 6,
                                    "components": [
                                        {
                                            "latest_reading": "-",
                                            "component_id": 339,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Probe 1",
                                            "latest_reading_tstamp": "-"
                                        },
                                        {
                                            "latest_reading": "-",
                                            "component_id": 333,
                                            "alarm_cnt": 0,
                                            "component_type": "Digital - Input",
                                            "component_name": "Door",
                                            "latest_reading_tstamp": "-"
                                        },
                                        {
                                            "latest_reading": "-",
                                            "component_id": 334,
                                            "alarm_cnt": 0,
                                            "component_type": "Digital - Input",
                                            "component_name": "Mains Power",
                                            "latest_reading_tstamp": "-"
                                        }
                                    ]
                                },
                                {
                                    "asset_id": 27,
                                    "asset_name": "Offices",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 3,
                                    "components": [
                                        {
                                            "latest_reading": "25.4°C",
                                            "component_id": 178,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Boardroom Temperature",
                                            "latest_reading_tstamp": "2014-08-18 12:50:00"
                                        },
                                        {
                                            "latest_reading": "Probe Err. (OC)",
                                            "component_id": 179,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "ICE 3 A1 -  Temperature",
                                            "latest_reading_tstamp": "2014-10-22 14:01:00",
                                            "sensor_error": true
                                        },
                                        {
                                            "latest_reading": "25.7°C",
                                            "component_id": 182,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "ICE3 - Ian's Office",
                                            "latest_reading_tstamp": "2014-10-22 14:01:00"
                                        }
                                    ]
                                },
                                {
                                    "asset_id": 26,
                                    "asset_name": "Peter Lamonts Fridge",
                                    "alarm_cnt": 3,
                                    "active_component_cnt": 5,
                                    "components": [
                                        {
                                            "latest_reading": "25.4°C",
                                            "component_id": 175,
                                            "alarm_cnt": 1,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Top Probe Temperature",
                                            "latest_reading_tstamp": "2014-08-18 12:50:00"
                                        },
                                        {
                                            "latest_reading": "25.4°C",
                                            "component_id": 176,
                                            "alarm_cnt": 1,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Mid Probe Temperature",
                                            "latest_reading_tstamp": "2014-08-18 12:50:00"
                                        },
                                        {
                                            "latest_reading": "25.4°C",
                                            "component_id": 177,
                                            "alarm_cnt": 1,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Bottom Probe Temperature",
                                            "latest_reading_tstamp": "2014-08-18 12:50:00"
                                        },
                                        {
                                            "latest_reading": "On",
                                            "component_id": 183,
                                            "alarm_cnt": 0,
                                            "component_type": "Digital - Input",
                                            "component_name": "Mains Power Peter Lamonts Fridge",
                                            "latest_reading_tstamp": "2014-08-18 12:50:00"
                                        },
                                        {
                                            "latest_reading": "Open",
                                            "component_id": 184,
                                            "alarm_cnt": 0,
                                            "component_type": "Digital - Input",
                                            "component_name": "Door Peter Lamonts Fridge",
                                            "latest_reading_tstamp": "2014-08-18 12:50:00"
                                        }
                                    ]
                                },
                                {
                                    "asset_id": 28,
                                    "asset_name": "Zero Fridge  Freezer",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 3,
                                    "components": [
                                        {
                                            "latest_reading": "Probe Err. (OC)",
                                            "component_id": 95,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Zero Freezer",
                                            "latest_reading_tstamp": "2014-08-18 12:20:00",
                                            "sensor_error": true
                                        },
                                        {
                                            "latest_reading": "Probe Err. (OC)",
                                            "component_id": 96,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Zero Fridge",
                                            "latest_reading_tstamp": "2014-08-18 12:20:00",
                                            "sensor_error": true
                                        },
                                        {
                                            "latest_reading": "",
                                            "component_id": 103,
                                            "alarm_cnt": 0,
                                            "component_type": "Digital - Input",
                                            "component_name": "Mains Power",
                                            "latest_reading_tstamp": "2014-08-18 12:20:00"
                                        }
                                    ]
                                }
                            ],
                            "site_id": 14,
                            "site_name": "21 Cradock Avenue"
                        }
                    ],
                    "region_name": "Rosebank",
                    "region_id": 3
                },
                {
                    "sites": [
                        {
                            "assets": [
                                {
                                    "asset_id": 44,
                                    "asset_name": "Dions Kitchen",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 1,
                                    "components": [
                                        {
                                            "latest_reading": "19.1°C",
                                            "component_id": 291,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "Ambient (Ice3)",
                                            "latest_reading_tstamp": "2014-10-22 21:51:00"
                                        }
                                    ]
                                },
                                {
                                    "asset_id": 31,
                                    "asset_name": "Vaccine Fridge",
                                    "alarm_cnt": 0,
                                    "active_component_cnt": 6,
                                    "components": [
                                        {
                                            "latest_reading": "30.3°C",
                                            "component_id": 87,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "A1:(Fridge) Ambient Temperature (BC540)",
                                            "latest_reading_tstamp": "2014-10-30 14:20:00"
                                        },
                                        {
                                            "latest_reading": "28.9°C",
                                            "component_id": 88,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "A2:Fridge Temp (BC540)",
                                            "latest_reading_tstamp": "2014-10-30 14:20:00"
                                        },
                                        {
                                            "latest_reading": "29.7°C",
                                            "component_id": 89,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "A3:Fridge (BC540)",
                                            "latest_reading_tstamp": "2014-10-30 14:20:00"
                                        },
                                        {
                                            "latest_reading": "6.6°C",
                                            "component_id": 21,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "ICE3 - A1 Fridge section",
                                            "latest_reading_tstamp": "2014-10-22 21:51:00"
                                        },
                                        {
                                            "latest_reading": "-14.9°C",
                                            "component_id": 22,
                                            "alarm_cnt": 0,
                                            "component_type": "Analogue - Input",
                                            "component_name": "ICE3 - A2 Freezer section",
                                            "latest_reading_tstamp": "2014-10-22 21:51:00"
                                        },
                                        {
                                            "latest_reading": "",
                                            "component_id": 25,
                                            "alarm_cnt": 0,
                                            "component_type": "Digital - Input",
                                            "component_name": "Mains Power",
                                            "latest_reading_tstamp": "2014-10-30 14:20:00"
                                        }
                                    ]
                                }
                            ],
                            "site_id": 2,
                            "site_name": "37 Wandel Ave"
                        }
                    ],
                    "region_name": "Sandton",
                    "region_id": 2
                }
            ]
        }
    }
}
我使用json2csharp创建了这些类:

    public class Response
    {
        public string hash { get; set; }
        public string resp_code { get; set; }
        public int code { get; set; }
    }

    public class Component
    {
        public string latest_reading { get; set; }
        public int component_id { get; set; }
        public int alarm_cnt { get; set; }
        public string component_type { get; set; }
        public string component_name { get; set; }
        public string latest_reading_tstamp { get; set; }
        public bool? sensor_error { get; set; }
    }

    public class Asset
    {
        public int asset_id { get; set; }
        public string asset_name { get; set; }
        public int alarm_cnt { get; set; }
        public int active_component_cnt { get; set; }
        public List<Component> components { get; set; }
    }

    public class Site
    {
        public List<Asset> assets { get; set; }
        public int site_id { get; set; }
        public string site_name { get; set; }
    }

    public class Region
    {
        public List<Site> sites { get; set; }
        public string region_name { get; set; }
        public int region_id { get; set; }
    }

    public class Company
    {
        public int company_id { get; set; }
        public string company_name { get; set; }
        public int alarm_cnt { get; set; }
        public List<Region> regions { get; set; }
    }

    public class Structure
    {
        public Company company { get; set; }
    }

    public class RootObject
    {
        public Response response { get; set; }
        public Structure structure { get; set; }
    }
公共类响应
{
公共字符串哈希{get;set;}
公共字符串响应代码{get;set;}
公共整数代码{get;set;}
}
公共类组件
{
公共字符串最近读取{get;set;}
公共int组件_id{get;set;}
公共整数报警{get;set;}
公共字符串组件_类型{get;set;}
公共字符串组件_name{get;set;}
公共字符串最新读取\u tstamp{get;set;}
公共布尔?传感器_错误{get;set;}
}
公共类资产
{
公共int资产_id{get;set;}
公共字符串资产名称{get;set;}
公共整数报警{get;set;}
public int active_component_cnt{get;set;}
公共列表组件{get;set;}
}
公共类网站
{
公共列表资产{get;set;}
public int site_id{get;set;}
公共字符串站点名称{get;set;}
}
公共类区域
{
公共列表站点{get;set;}
公共字符串区域_name{get;set;}
公共整数区域_id{get;set;}
}
公营公司
{
public int company_id{get;set;}
公共字符串公司名称{get;set;}
公共整数报警{get;set;}
公共列表区域{get;set;}
}
公共阶级结构
{
上市公司{get;set;}
}
公共类根对象
{
公共响应{get;set;}
公共结构结构{get;set;}
}
这是我到目前为止所做的

var client = new RestClient() { BaseUrl = url };
var request = new RestRequest()
{ 
    Resource = "", 
    Method = Method.GET, 
    RequestFormat = DataFormat.Json 
};

request.OnBeforeDeserialization = resp => { resp.ContentType = "application/json"; };

client.ExecuteAsync(request, (response, handle) =>
{
    RestSharp.Deserializers.JsonDeserializer deserial = 
        new RestSharp.Deserializers.JsonDeserializer();
    var resp = deserial.Deserialize<List<RootObject>>(response);
    var JSONObj = deserial.Deserialize<Dictionary<string, string>>(response);

    string structure = JSONObj["structure"].ToString();
}
var client=new RestClient(){BaseUrl=url};
var request=new RestRequest()
{ 
资源=”,
Method=Method.GET,
RequestFormat=DataFormat.Json
};
request.OnBeforeDeserialization=resp=>{resp.ContentType=“application/json”;};
client.ExecuteAsync(请求,(响应,句柄)=>
{
RestSharp.Deserializers.JsonDeserializer Deserializer=
新的RestSharp.Deserializers.JsonDeserializer();
var resp=反序列化。反序列化(响应);
var JSONObj=deserial.Deserialize(响应);
string structure=JSONObj[“structure”].ToString();
}
这给了我“结构”下的所有数据

我需要将RegionName列在列表框中;我需要获得每个区域下的站点列表;我还需要根据所选字段获得每个站点下列出的资产

我现在的问题是使用数据。我使用的是RestSharp客户端。
我必须相应地对数据进行分组:所有区域、站点、资产。站点必须根据它们所属的区域进行分组;资产也必须根据它们所属的站点进行分组。有人知道我如何做到这一点吗?请提供任何帮助。

JSON表示JavaScript对象符号

要反序列化,您应该创建一个C#对象,它看起来像那个JSON对象(相同的属性名,不同的数据类型)

然后可以使用

new JavaScriptSerializer().Deserialize<MyJSONObjectType>(jsonstring);
可以反序列化到对象中

public class MyJSONObjectType {
    public bool success;
    public List<MySubObj> data;
}
public class MySubObj {
    public int id;
    public string name;
}
公共类MyJSONObjectType{
公共事业的成功;
公开名单数据;
}
公共类MySubObj{
公共int id;
公共字符串名称;
}

thanx..但是我反序列化了JSON响应..我的问题是安排数据并在相关列表框中摸索..我使用了RestSharp.Deserializers.jsondeseserializers.o,事实上,你的问题是绝对不清楚的,如果没有误导的话。请以我们能够理解你的问题的方式发布你的问题。特别是,发布你的代码。我编辑了我的问题并包含了我的代码,希望我现在有点道理。请遵循此链接。我编辑了你的问题,以包含链接中重新格式化的JSON。我删掉了部分内容以使其符合字符限制。剩余的JSON通过jsonlint.com验证,我认为仍然与你使用的结构通信。t汉克斯·布莱恩……现在你知道我怎样才能用这个完成我需要完成的事情吗?
public class MyJSONObjectType {
    public bool success;
    public List<MySubObj> data;
}
public class MySubObj {
    public int id;
    public string name;
}