The code below works on a live site but I can\'t get it to run on the site jsfiddle .
See this for example.
Can anyone tell me why it\'s not working on jsfid
Look at:
https://stackoverflow.com/a/4935684/6796393
Or it is better to see this one:
https://stackoverflow.com/a/19110630/6796393
Here is what I tested:
function testJSON() {
var jsonString = '{"param1":"123","param2":"XXX78","param3":"11378"}';
var tmp_obj = eval('(' + jsonString + ')');
document.getElementById("result").innerHTML = tmp_obj.param2;
}
and
function testJSON() {
var jsonString = '{"param1":"123","param2":"XXX78","param3":"11378"}';
var tmp_obj = JSON.parse(jsonString);
document.getElementById("result").innerHTML = tmp_obj.param2;
}
It is better to use the second aproach.
P.S.> I came from How to parse parameters from JSON String using JS?