Home  >  Article  >  Web Front-end  >  Example explanation of json loop iteration parsing

Example explanation of json loop iteration parsing

零下一度
零下一度Original
2017-07-24 15:19:371573browse

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn