javascript - How to write this in json format? -
i have code stores data in array. want output on json format. currently, can convert input data json i'm not sure how change code works object. example code on lines :
target = (children[p] || (children[p] = []));
and
target.push({value:item});
any ideas?
for (var = 0, len = arry.length; < len; ++i) { var item = arry[i], p = item.parent, target = []; if(p == rootid) { target = roots; } else { target = (children[p] || (children[p] = [])); } target.push({ value: item });
}
you can serialize arbitrary javascript object json string calling json.stringify()
.
that may or may not want.
Comments
Post a Comment