This article mainly introduces the relevant information of JavaScript parsing any form of json tree structure display. Friends who need it can refer to
Display on the page When json is formed into a tree structure, the json obtained is often not in the standard format of ztree, and jsonloop needs to be parsed iteratively. Even non-standard json can be displayed in tree shape:
var arrayJsonContent=[]; //节点类 var JsonNodes = { id:"", name:"", pId:"", content:"", //location:"", linklocation:"", open:false }; //循环迭代解析json function buildTree(o,params){ for( var child in o){ var param =params+"?"+child; var JsonNodes={ id:param, pId:params, name:child }; arrayJsonContent.push(JsonNodes); if(typeof o[child] == "object"){ buildTree(o[child],param,loca); }else{ var JsonNodes={ id:param, pId:params, name:child, content:o[child] }; arrayJsonContent.push(JsonNodes); } }
The above is the detailed content of Example explanation of json loop iteration parsing. For more information, please follow other related articles on the PHP Chinese website!