我有一个字典形式的字符串,方式如下:var str1= '{ "T1" : "1"},{ "T1" : "2"}, { "T2" : "3"},{ "T2" : "4"}, { "T2" : "5"}, { "T3" : "6"}, { "T3" : "7"},{ "T3" : "8"},{ "T2" : "9"}, { "T2" : "10"}, { "T1" : "11"}, { "T1" : "12"}';
请给出任何想法如何转换它,使其表现为树状结构。即 T1 将在循环中搜索到下一个 T1,并将 T1 及其值附加到当前迭代项中,类似于 T2 等等。例如 str2。
str2='{ "T1" : "1"} ,{ "T1" : "2", "T2" : "3"},{ "T1" :"2", "T2" : "4"}, { "T1" : "2", "T2" : "5", "T3" : "6"}, { "T1" : "2", "T2" : "5", "T3" : "7"},{ "T1" : "2", "T2" : "5", "T3" : "8"},
{ "T1" : "2", "T2" : "9"},{ "T1" : "2", "T2" : "10"}, { "T1" : "11"}, { "T1" : "12"}';