【发布时间】:2012-10-08 02:57:43
【问题描述】:
我有一个字符串列表,这些字符串表示分层数据并且用连字符分隔(3 个连字符表示分隔)。我正在尝试将此列表转换为 JSON 字符串,以便可以将其绑定到树控件。
我正在寻找一个 C# 示例。
列表可以如下(列表不是完整的列表,在某些情况下它可以有 7 个节点,但您可以理解):
Automotive Electronics
Automotive Electronics---Body Electronics
Automotive Electronics---Body Electronics---Access Control Systems
Automotive Electronics---Body Electronics---Body Control Modules
Automotive Electronics---Driver Information
Automotive Electronics---Driver Information---Clocks
Automotive Electronics---Driver Information---Compass Systems
Automotive Electronics---HomeL
Automotive Electronics---Infotainment & Connectivity
Automotive Electronics---Infotainment & Connectivity---Handsfree Systems
Automotive Interiors
Automotive Interiors---Door Panels
Automotive Interiors---Floor Consoles
Automotive Interiors---Headliners & Overhead Systems
Automotive Interiors---Overhead Consoles
Automotive Seating
Automotive Seating---Complete Seats
Automotive Seating---Complete Seats---SuperThin Seats
【问题讨论】:
-
这个数据会经常变化吗?你会输入这个还是从其他来源提取它?
-
它来自一个数据库,所以它有可能改变......我基本上是把这些作为一个列表从数据库中拉出来
-
好吧,它们会以分层的形式出现吗?
-
他们会完全按照我上面的列表进来......也就是说,已经按顺序排列了,并且父母总是在孩子之前。
-
您的预期输出是什么?我假设您希望它采用某种格式(您未在此处提供)。
标签: c# json string hierarchical delimited