-1
[
    {
        "Text": "Topaz Building",
        "Value": "101",
        "Expanded": false,
        "Items": [
            {
                "Text": "Floor1",
                "Value": "102",
                "Expanded": false,
                "Items": [
                    {
                        "Text": "Room1",
                        "Value": "105",
                        "Expanded": false,
                        "Items": [
                            {
                                "Text": "Cab1",
                                "Value": "107",
                                "Expanded": false
                            },
                            {
                                "Text": "Cab2",
                                "Value": "108",
                                "Expanded": false,
                                "Items": [
                                    {
                                        "Text": "Sub1",
                                        "Value": "109",
                                        "Expanded": false
                                    },
                                    {
                                        "Text": "Sub2",
                                        "Value": "110",
                                        "Expanded": false
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "Text": "Room2",
                        "Value": "106",
                        "Expanded": false
                    }
                ]
            },
            {
                "Text": "Floor2",
                "Value": "103",
                "Expanded": false,
                "Items": [
                    {
                        "Text": "Room1",
                        "Value": "111",
                        "Expanded": false
                    },
                    {
                        "Text": "Room2",
                        "Value": "112",
                        "Expanded": false,
                        "Items": [
                            {
                                "Text": "Cab1",
                                "Value": "113",
                                "Expanded": false,
                                "Items": [
                                    {
                                        "Text": "Sub1",
                                        "Value": "115",
                                        "Expanded": false
                                    },
                                    {
                                        "Text": "Sub2",
                                        "Value": "116",
                                        "Expanded": false
                                    }
                                ]
                            },
                            {
                                "Text": "Cab2",
                                "Value": "114",
                                "Expanded": false
                            }
                        ]
                    }
                ]
            },
            {
                "Text": "Floor3",
                "Value": "104",
                "Expanded": false
            }
        ]
    }
]

以上是我必须操作的json

如果我从他们那里发送/搜索一个值(105),我需要获取它的所有孩子的 json 数据(107,108,109,110)。请帮助我

4

1 回答 1

1

在 C# 中设计一些类,通过序列化 JSON 数据作为字符串读取,然后使用 LINQ 进行选择,一直通过 Items 属性进行查询。

using System;
using System.Runtime.Serialization;

namespace YourNamespace
{
    [Serializable]
    [DataContract]
    public class Data
    {
        [DataMember(Name = "Text"]
        public string Text{get;set;}

        [DataMember(Name = "Value"]
        public string Value{get;set;}

        [DataMember(Name = "Expanded"]
        public bool Expanded{get;set;}

        [DataMember(Name = "Items"]
        public Data[] Items{get;set;}
    }
}
于 2013-08-23T10:59:29.827 回答