as3corelib
as3corelib包裡有一個JSON類,可以將一個AS Object轉換為JSON格式的字符串,例如:
var obj:Object = { username : "Oscar Tong", password : "123456", age : 23, male: true, contacts: { mobile: "13800138000", phone: "020-39322849", addr: "guangdong university of technology" } } var json:String = JSON.encode(obj); trace(json); 輸出JSON格式的字符串為: {"username":"Oscar Tong", "age":23, "password":"123456", "male":true, "contact": {"addr":"guangdong university of technology", "phone":"020-39322849", "mobile":"13800138000"} }
貌似輸出結果的順序有點亂了,另外JSON還有一個靜態方法decode,可以將JSON格式的字符串轉換為一個AS Object,具體自己看看包裡附帶的reference吧~~
0 意見