日期:2014-05-18 浏览次数:20742 次
var array = {'{':1,'}':-1},max=0,count=0;
var json = "{'name':'t1','children':[{'children':[{'name':'t3'},{'name':'t4'},{'children':[{'name':'t5'},{'name':'t6'}]}]},{'name':'t2'}]}";
for (var i = 0, length = json.length; i < length; i++) {
var result = array[json.charAt(i)];
if (!result) continue;
count+=result;
if (count>max) {
max = count;
}
}
if (count != 0) {
alert('json format error!');
} else {
alert('max:'+max);
}