1. Currently there is a very arbitrary interface API, and the data it provides is very unreasonable
2. The data is as follows
var json = [{"mainId": 1, "title": "abc", "createdate": "2017-06-28"},{"mainId": 2, "title": "ddddd", "createdate": "2017-06-25"}];
var json1 = [{"childId":1, "mainId": 1, "childname": "cname"},{"childId":2, "mainId": 1, "childname": "cname2"},{"childId":3, "mainId": 2, "childname": "cname3"},{"childId":4, "mainId": 2, "childname": "cname4"}];
var json2 = [{"childchildId":1, "childId": 1, "childname": "cname"},{"childchildId":2, "childId": 1, "childname": "cname2"},{"childchildId":3, "childId": 2, "childname": "cname3"},{"childchildId":4, "childId": 2, "childname": "cname4"},{"childchildId":5, "childId": 3, "childname": "cname"},{"childchildId":6, "childId": 3, "childname": "cname2"},{"childchildId":7, "childId": 4, "childname": "cname3"},{"childchildId":8, "childId": 4, "childname": "cname4"}];
3. I want to merge them into a json as follows:
var result = [{"mainId":1, "title": "abc", "createdate": "2017-06-28", child:[{"childId":1, "mainId": 1, "childname": "cname", childchild:[{"childchildId":1, "childId": 1, "childname": "cname"},{"childchildId":2, "childId": 1, "childname": "cname2"}]},{"childId":2, "mainId": 1, "childname": "cname2", childchild:[{"childchildId":3, "childId": 2, "childname": "cname3"},{"childchildId":4, "childId": 2, "childname": "cname4"}]}]
Is there a good way?
Well, I just don’t want to write a loop
Reduce reconstruction:
php, step by step
Normal output
It’s very useful, but the browser may prompt that eval is harmful. If you want to remove this, Baidu has a method. I forgot the details