Pavankumar
Pavankumar

Reputation: 21

parsing json response array in javascript

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

Upvotes: 0

Views: 54

Answers (1)

Afsar
Afsar

Reputation: 3124

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);
    }

Upvotes: 1

Related Questions