JSON Encode และ Decode ใน Flash Builder 4.6 by

30
Apr
0

สืบเนื่องจาก บทความนี้ ผมต้องการที่จะส่งข้อมูลจาก php มายัง flex ในรูปแบบ JSON แต่ว่าในกระทู้นี้จำเป็นต้องหาไฟล์ corelib.swc หรือ as3corelib.swc แล้ว import เข้ามาช่วยทำการ encode และ decode ข้อมูลที่ส่งมาจากไฟล์ php แต่สำหรับ Flash Builder 4.6 ที่ผมใช้อยู่นั้น ผมก็ได้ลองทำตามกระทู้นี้ทุกขั้นตอน แต่ก็ยังเกิด error message ตามนี้

1120: Access of undefined property JSON.

Can not resolve a multiname reference unambiguously. JSON (from C:\Program Files\Adobe\Adobe Flash Builder 4.6\sdks\4.6.0\frameworks\libs\player\11.1\playerglobal.swc(JSON, Walker)) and com.adobe.serialization.json:JSON (from C:\Users\shippo\Downloads\corelib.swc(com.adobe.serialization.json:JSON)) are available.

ทำให้ทราบว่า class JSON มันดันซ้ำกันระหว่างไฟล์ playerglobal.swc (ซึ่งมีมากับ Flash Builder 4.6) และ corelib.swc มันจึงรันไม่ได้ซักที ก็พยายามเสิร์ชหาใน Google จนได้ความว่าใน Flash Builder 4.6 นั้น การที่จะ Encode หรือ Decode ข้อมูลที่มาในรูปแบบ JSON สามารถทำเลยโดย

1. การ decode JSON

var aData:* = JSON.parse(e.result as String);

จากตัวอย่างข้างต้นเป็นการ decode JSON ใน Flash Builder 4.6 แทนการใช้ JSON.decode
2. การ encode JSON

var objStr:String = JSON.stringify( {name:”Todd Anderson”, company:”Infrared5″, phone:15558576309}, deflate );

จากตัวอย่างข้างต้นเป็นการ encode JSON ใน Flash Builder 4.6 แทนการใช้ JSON.encode
ซึ่งทั้ง JSON.parse และ JSON.stringify เป็นเมธอดที่มีอยู่แล้วในไฟล์ playerglobal.swc หากต้องการเพียงแค่ encode และ decode ข้อมูลรูปแบบ JSON เราไม่จำเป็นต้องใช้ corelib.swc หรือ as3corelib.swc ก็ได้

Enjoy this article?

Consider subscribing to our RSS feed!

ไม่มีความเห็น

ยังไม่มีความเห็น

ใส่ความเห็น

RSS feed for comments on this post

 เราชนะรอบ 4 | ยืมเงิน 3000 ด่วน | แอพกู้เงิน | แอพเงินด่วน | สินเชื่อออนไลน์อนุมัติทันที | Site Map | กู้เงินก้อน | กระเป๋าตัง | thisshop และ ยืมเงินฉุกเฉิน 5000 ด่วน