json不能用for-of循环,会报错
可以用for-in循环:
1 var json = {'a':'apple','b':'banana','c':'orange','d':'pear'};
2 for(var name in json){
3 console.log(name);// a b c d
4 //打印的name值是字符串,所以用json['d']的方式输出
5 console.log(json[name]);// apple banana orange pear
6 // apple
7 console.log(json.a);
8 // pear
9 console.log(json['d']);
10 }