0

I have a json arry

{
    "result": "sucess",
    "senderids": [{
        "id": "2",
        "senderid": "powers",
        "status": "0",
        "type": "2",
        "availa": "0",
        "user": "admin"
    }, {
        "id": "3",
        "senderid": "powert",
        "status": "0",
        "type": "2",
        "availa": "0",
        "user": "admin"
    }, {
        "id": "4",
        "senderid": "powerd",
        "status": "0",
        "type": "2",
        "availa": "0",
        "user": "admin"
    }, {
        "id": "5",
        "senderid": "pavank",
        "status": "0",
        "type": "1",
        "user": "pavan"
    }]
}

Javascript:

var res = xhr.responseText;
var s = res.senderids;
for (i = 0; i < s.senderids.length; i++) {
    var contact = JSON.parse(s.senderids[i].senderid);
    alert(contact);
}

How i can parse this json array using JSON.parse. I have tried this code

thanks in advance

2
  • i have tried the following code var res = xhr.responseText; var s=res.senderids; for(i=0;i<s.senderids.length;i++) { var contact = JSON.parse(s.senderids[i].senderid); alert(contact) } Commented Jan 30, 2016 at 7:17
  • var s = res.senderids; this only will work after you've parsed res. JSON.parse in the loop is way too late :) Commented Jan 30, 2016 at 7:26

1 Answer 1

1

Try this:

var res = JSON.parse(xhr.responseText);
    var s = res.senderids;
    for (i = 0; i < s.senderids.length; i++) {
        var contact = s.senderids[i].senderid;
        alert(contact);
    }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.