【发布时间】:2017-09-14 19:08:18
【问题描述】:
我有一个 JSON 数组。我尝试转换嵌套分层树。但它没有用。我需要一个使用这个 JSON 的层次树。
这是我的数据:
[{
"_id" : "59b65ee33af7a11a3e3486c2",
"C_TITLE" : "Sweet and Snacks",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets.jpg",
"C_STATUS" : "Active"
}
{
"_id" : "59b663d709da571dc3d79f49",
"C_TITLE" : "Groceries",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b663d709da571dc3d79f49_grocery.jpg",
"C_STATUS" : "Active"
},
{
"_id" : "59b6648209da571dc3d79f4a",
"C_TITLE" : "Dals & Pulses",
"C_PARENT" : "59b663d709da571dc3d79f49",
"C_ICON" : "",
"C_IMAGE" : "59b6648209da571dc3d79f4a_dals.jpg",
"C_STATUS" : "Active"
},
{
"_id" : "59b6657509da571dc3d79f4c",
"C_TITLE" : "Rice & Rice products",
"C_PARENT" : "59b663d709da571dc3d79f49",
"C_ICON" : "",
"C_IMAGE" : "59b6657509da571dc3d79f4c_rice.jpg",
"C_STATUS" : "Active"
}]
我需要这样的输出
[
{
" _id" : "59b65ee33af7a11a3e3486c2",
"C_TITLE" : "Sweet and Snacks",
"C_PARENT" : "0",
"C_ICON" : "",
"C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets.jpg",
"C_STATUS" : "Active",
children:[]
}
]
基于检查 C_PARENT 和 _id。
【问题讨论】:
-
你能添加你预期的输出吗
-
[ { "_id" : "59b65ee33af7a11a3e3486c2", "C_TITLE" : "糖果和零食", "C_PARENT" : "0", "C_ICON" : "", "C_IMAGE" : "59b65ee33af7a11a3e3486c2_sweets。 jpg”、“C_STATUS”:“活动”、儿童:{“_id”:“ghhgfhfhhhg”、“C_TITLE”:“糖果和零食”、“C_PARENT”:“59b65ee33af7a11a3e3486c2”、“C_ICON”:“”、“C_IMAGE” : "59b65ee33af7a11a3e3486c2_sweets.jpg", "C_STATUS" : "活动", } } ]
-
感谢您的回复。我需要以上输出。
-
您应该更新问题中的预期输出,最好让我们看到@sarankani
标签: javascript json