Loop and get key/value pair for JSON array using jQuery

后端 未结 6 554
醉话见心
醉话见心 2020-11-29 23:31

I\'m looking to loop through a JSON array and display the key and value.

It should be a simplified version of the following post, but I don\'t seem to have the syn

6条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 00:03

    Parse the JSON string and you can loop through the keys.

    var resultJSON = '{"FirstName":"John","LastName":"Doe","Email":"johndoe@johndoe.com","Phone":"123 dead drive"}';
    var data = JSON.parse(resultJSON);
    
    for (var key in data)
    {
        //console.log(key + ' : ' + data[key]);
        alert(key + ' --> ' + data[key]);
    }

提交回复
热议问题