JSON produces smaller documents, and JSON is certainly easier to use in JavaScript. XMLHttpRequest parses XML documents for you whereas you have to manually parse JSON, but is parsing JSON slower than parsing XML?
When it comes to making AJAX behave like a desktop application, speed is everything, and clearly, , JSON is a winner..
Test in your browser -Benchmarking AJAX - JSON vs XML.
Showing posts with label json. Show all posts
Showing posts with label json. Show all posts
Wednesday, September 24, 2008
Tuesday, September 2, 2008
MySQL to JSON
Add to simplicity and might even save some valuable server time. If you're running MySQL 4.1 or later you can use the nifty function GROUP_CONCAT() together with the normal CONCAT() function to build all your JSON straight from your SQL query.
Our SQL table.
| username | |
| tommy | tommy@tommysplace.com |
| jane | jane@examples.com |
| jack | jack@iford.com |
SELECT
CONCAT("[",
GROUP_CONCAT(
CONCAT("{username:'",username,"'"),
CONCAT(",email:'",email),"'}")
)
,"]")
AS json FROM users;[
{username:'tommy',email:'tommy@tommysplace.com'},
{username:'jane',email:'jane@examples.com'},
{username:'jack',email:'jack@jiford.com'}
]
Labels:
ajax,
javascript,
json,
mysql,
sql
Subscribe to:
Posts (Atom)