1
[  
   Object   {  
      id: "1",
      name: "sakthivel"
   },
   Object   {  
      id: "2",
      name: "sathish"
   },
   Object   {  
      id: "3",
      name: "saravanan"
   },
   Object   {  
      id: "4",
      name: "murugan"
   },
   Object   {  
      id: "5",
      name: "velmurugan"
   },
   Object   {  
      id: "6",
      name: "vadivelan"
   }
]
3
  • 1
    Your JSON is Invalid. Commented Sep 9, 2015 at 11:37
  • 1
    var json = (function () { var json = null; $.ajax({ 'async': false, 'global': false, 'url': "localhost/download/index.php/home/getarray", 'dataType': "json", 'success': function (data) { json = data; } }); return json; })(); console.log(json); Commented Sep 9, 2015 at 12:07
  • Updated answer. Take a look Sakthivel. Commented Sep 9, 2015 at 12:11

1 Answer 1

2

Try JSON.parse() as mentioned below:

var json = '{"value":"validJSON"}';
var obj = JSON.parse(json);
console.log(json);

Full snippet:

var json = (function() {
    var json = null;
    $.ajax({
        'async': false,
        'global': false,
        'url': "localhost/download/index.php/home/getarray";,
        'dataType': "json",
        'success': function(data) {
            var parsed_result = JSON.parse(data);  //parsing here
            return parsed_result; //return when data is parsed successfully
        }
    });
})();
console.log(json);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.