简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM