Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Converting a Tree table into JSON Tree, How?

$
0
0

Hi all,

i have a table containing a tree structure like this

id   parent_id     name

0       -1            sometext

1        0            sometext

2        0            sometext

3        0            sometext

4        0            sometext

5        0            sometext

6        1            sometext

7        1            sometext

8        1            sometext

9        2            sometext

10       2            sometext

and i want to convert this tabale into json tree like this

{"children": [ {"id":0,"text":" sometext ","children":[ {"text":" sometext ","id":1,"children":[ {"text": " sometext ", "id": 6,
            }
            ,
            {"text": " sometext ", "id": 7,
            }
            ,
            {"text": " sometext ", "id": 8,
            }
            ]
        }
        ,
        {"text":" sometext ","id":2,"children":[ {"text": " sometext ", "id": 9,
            }
            ,
            {"text": " sometext ", "id": 10,
            }
            ]
        }
        ,
        {"text": " sometext ", "id": 3,
        }
        ,
        {"text": " sometext ", "id": 4,
        }
        ,
        {"text": " sometext ", "id": 5,
        }
        ]
    }
    ]
}

how can i achieve this? please help


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>