1

I'm trying to parse a JSON String , but the parsed value is undefined . Here is jsfiddle

    <input type="submit" onclick=testJSON() value="Test"/> 
    <div id = "result">Test </div> 

<script> 
    function testJSON() { 

    var jsonString = '{"param1":"123","param2":"XXX78","param3":"11378"}'; 

    document.getElementById("result").innerHTML = (JSON.parse(jsonString)).param2;

    } 
</script> 
john
  • 647
  • 5
  • 23
  • 53

1 Answers1

3

The code is working fine - the problem here is in JSFiddle, as it's set to just run the JS code when the document is loaded, so the function doesn't get registered - here's the relevant option:

enter image description here

fstanis
  • 5,234
  • 1
  • 23
  • 42