-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
            }
        ]
    }
]

Above is json which i have to manipulate

if i send/search an value(105) from their i need to get all childs json data of it(107,108,109,110).please help me with that

musefan
  • 47,875
  • 21
  • 135
  • 185
env
  • 1

1 Answers1

1

Design some classes in C# to read in the JSON data as a string by serializing it then make your selection using LINQ to query all the way down through the Items property.

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;}
    }
}
Lorcan O'Neill
  • 3,303
  • 1
  • 25
  • 24
  • But i dont want like this i want i send one value based on i have to get childs of it – env Aug 23 '13 at 11:02
  • Considering that you specified C# in your question, I'm offering a C# answer. I think you may be asking a different question so in which case I would advise you to rephrase your question more clearly please. – Lorcan O'Neill Aug 23 '13 at 11:06
  • c# only ,please give me how to parse json and quering the json format – env Aug 23 '13 at 11:17
  • i tell you clearly ,i get above json format what i want is querying on – env Aug 23 '13 at 11:22
  • the json format .i send one child value as input i want childs of it – env Aug 23 '13 at 11:23
  • Once again I fail to see what your issue here is. Read that string into a C# program and serialize it into the class I've given you above. It doesn't matter if it's only the "child" JSON you have, it's the same object pattern so this will work. If you don't know how to serialize/deserialize into JSON, the package described here can be quite useful http://stackoverflow.com/questions/4749639/deserializing-json-to-net-object-using-newtonsoft-or-linq-to-json-maybe – Lorcan O'Neill Aug 27 '13 at 08:26