2

Script

var data = '{"Err0":"Only letters and white space allowed in Name"}';
try {
                  //convert to json string
                      arr = $.parseJSON(data); //convert to javascript array
                      arr.each(function(key,value){
                       console.log(value);
                  });
              } catch (e) {
                  $("#id").val(data);
              }

Trying to get the value of the json but its throwing error

Any help

Thanks

4
  • 1
    $data != data .. That error shouldn't have been a pretty simple clue Commented Oct 26, 2015 at 13:46
  • @charlietfl updated my question Commented Oct 26, 2015 at 13:47
  • @Andreas it was a typo I fixed it Commented Oct 26, 2015 at 13:47
  • 1
    $.parseJSON() returns an object (and not a jQuery object) which has no .each() method Commented Oct 26, 2015 at 13:49

1 Answer 1

9

use below code

insteade of arr.each use $.each(arr,.

DEMO

var data= '{"Err0":"Only letters and white space allowed in Name"}';
arr = $.parseJSON(data); //convert to javascript array
$.each(arr,function(key,value){
    alert(value);
});
Sign up to request clarification or add additional context in comments.

2 Comments

@charlietfl that was a typo that I updated in my question , My actual mistake was arr.each() thanks anyways
@charlietfl check my answer again its not only typo . use of $.each function also wrong

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.