Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse json array using javascript

I have a json arry

    var students = {"apResults":[{"offid":"267","item_name":"","offer_name":"fsdfsf","stlongitude":"77.5945627","stlatitude":"12.9715987"},

{"offid":"265","item_name":"","offer_name":"vess offer shops","stlongitude":"","stlatitude":""},

{"offid":"264","item_name":"","offer_name":"vess ofer  shop","stlongitude":"","stlatitude":""},
{"offid":"263","item_name":"","offer_name":"ofer frm vess","stlongitude":"77.5943760","stlatitude":"12.9716060"},
{"offid":"262","item_name":"","offer_name":"offer hungamma","stlongitude":"77.5943760","stlatitude":"12.9716060"},
{"offid":"261","item_name":"","offer_name":"offer hungamma","stlongitude":"77.5943760","stlatitude":"12.9716060"},
{"offid":"260","item_name":"","offer_name":"offer1","stlongitude":"77.5943760","stlatitude":"12.9716060"},
{"offid":"259","item_name":"","offer_name":"offer","stlongitude":"77.5943760","stlatitude":"12.9716060"}]}

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

    for(i=0;i<students.apResults.length;i++)
{
    var contact = JSON.parse(students.apResults);
    var offid = contact.offid;
    alert(offid)    
}

But its giving an error JSON.parse: unexpected character.Edited my question

like image 504
Warrior Avatar asked Dec 02 '22 00:12

Warrior


1 Answers

That's not a json string, that's a regular javascript variable:

for(i=0;i<students.Maths.length;i++)
{
    var contact = students.Maths[i];
    var fullname = contact.Name;
    alert(fullname) 
}
like image 122
Evert Avatar answered Dec 20 '22 11:12

Evert