Showing posts with label JSON. Show all posts
Showing posts with label JSON. Show all posts

Monday, 16 July 2012

Introduction to JSON and PHP



ปัจจุบันการใช้งาน JSON เริ่มที่จะเข้ามาแทนที่ XML เนื่องจากมีขนาดเล็ก สามารถใช้งานได้โดยไม่จำเป็นต้องใช้ parser ที่วุ่นวาย ผู้ที่คิดค้น JSON format คือ Douglas Crockford ดังนั้นการเรียนรู้ที่จะใช้งาน JSON จึงเป็นสิ่งที่จำเป็น โดยเฉพาะ Web Developer สำหรับบทความที่ผมอยากจะแนะนำต่อไปนี้ เขียนขึ้นโดย Frank Lakatos มีชื่อว่า "Introduction to JSON and PHP" เป็นบทความที่เขียนเกี่ยวกับการประยุกต์ใช้งานร่วมกันระหว่าง JSON และ PHP โดยมีตัวอย่างการใช้งานทั้งทางฝั่ง Client Side (โดยใช้ jQuery และ AJAX) และ Server Side (PHP และ json_encode) สำหรับผู้ที่สนใจ สามารถเข้าไปอ่านบทความได้ที่นี่ครับ http://www.itnewb.com/tutorial/Introduction-to-JSON-and-PHP

แหล่งที่มา:
  1. http://www.itnewb.com/tutorial/Introduction-to-JSON-and-PHP
  2. http://en.wikipedia.org/wiki/JSON

Tuesday, 3 July 2012

jquery-json - simple ways to convert to JSON and back again



jQuery มีความสามารถในการ parse JSON string ไปเป็น JavaScript Object โดยใช้ method ที่มีชื่อว่า jQuery.parseJSON(json) แต่น่าแปลกใจว่า jQuery กลับไม่มี function ในการแปลง JavaScript กลับไปเป็น JSON string วันนี้ผมเลยอยากจะมาแนะนำ jQuery Plugin ตัวนึงที่จะช่วยเพิ่ม function ในการแปลงกลับไปกลับมาระหว่าง JSON String กลับ JavaScript Object แบบง่ายๆ Plugin ตัวนี้มีชื่อว่า "jquery-json" จะทำหน้าที่เพิ่มความสามารถให้ jQuery Object โดยเพิ่ม method ที่มีชื่อว่า toJSON (สำหรับแปลง JavaScript Object ไปเป็น JSON string) และ evalJSON (สำหรับแปลง JSON string กลับไปเป็น JavaScript Object) สำหรับใครที่สนใจ สามารถเข้าไป download ได้ที่นี่ครับ http://code.google.com/p/jquery-json/ สำหรับอีกทางเลือกนึงสำหรับผู้ที่ไม่อยากใช้ Plugin ตัวนี้ ก็สามารถไป download json2.js จาก http://www.json.org แล้วใช้ function ที่มีชื่อว่า JSON.stringify() ครับ

ตัวอย่างการใช้งาน jquery-json
แหล่งที่มา:
  1. http://code.google.com/p/jquery-json/
  2. http://www.json.org
  3. http://stackoverflow.com/questions/3904269/convert-object-to-json-string