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> 
1

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

2 Comments

@john We have a winner, this is just the solution
Not really, this is a comment, or at best a duplicate of the many, many similar questions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.