记录一下,一般使用JSON序列化一个对象成字符串描述时都比较难于阅读,特别是大量且复杂的数据时,如:
1 var s:String = '{"title":"Adobe Flash 11 Stage3D (Molehill)Game Programming","authors":["Christer Kaitila"],"edition":1,"year":2011}'; 2 var o:Object = JSON.parse(s); 3 trace(JSON.stringify(o));
得到:
1 {"title":"Adobe Flash 11 Stage3D (Molehill)Game Programming","year":2011,"edition":1,"authors":["Christer Kaitila"]}
我们可以操作第3个参数实现格式化一般可以用下面的两者写法:
1 var s:String = '{"title":"Adobe Flash 11 Stage3D (Molehill)Game Programming","authors":["Christer Kaitila"],"edition":1,"year":2011}'; 2 var o:Object = JSON.parse(s); 3 trace(JSON.stringify(o, null, "\t"));
得到:
1 { 2 "title": "Adobe Flash 11 Stage3D (Molehill)Game Programming", 3 "year": 2011, 4 "edition": 1, 5 "authors": [ 6 "Christer Kaitila" 7 ] 8 }
或者:
1 var s:String = '{"title":"Adobe Flash 11 Stage3D (Molehill)Game Programming","authors":["Christer Kaitila"],"edition":1,"year":2011}'; 2 var o:Object = JSON.parse(s); 3 trace(JSON.stringify(o, null, 4));
得到:
1 { 2 "title": "Adobe Flash 11 Stage3D (Molehill)Game Programming", 3 "year": 2011, 4 "edition": 1, 5 "authors": [ 6 "Christer Kaitila" 7 ] 8 }