JavaScript JSON encode/decode
// 1: JSON decode with JavaScript eval function
var jsontext1 = '({"id": 5, "url": "http://www.heig-vd.ch"})';
var object1 = eval(jsontext1);
console.log(object1);
// 2: JSON decode with browser native implementation
if (typeof JSON != "undefined") {
var jsontext2 = '{"id": 5, "url": "http://www.heig-vd.ch"}';
var object2 = JSON.parse(jsontext2);
console.log(object2);
}
// 3: JSON encode with browser native implementation
if (typeof JSON != "undefined") {
var object3 = new Object();
object3.id = 5;
object3.url = "http://www.heig-vd.ch";
var jsontext3 = JSON.stringify(object3);
console.log(jsontext3);
}
(see your debug console output)