How to loop through JSON array?

前端 未结 8 1647
鱼传尺愫
鱼传尺愫 2020-12-01 14:52

I have some JSON-code which has multiple objects in it:

[
    {
        \"MNGR_NAME\": \"Mark\",
        \"MGR_ID\": \"M44\",
        \"EMP_ID\": \"1849\"
           


        
8条回答
  •  甜味超标
    2020-12-01 15:44

    You can iterate over the collection and check each object if it contains the property:

    var count = 0;
    var i;
    for(i = 0; i < jsonObj.length; i += 1) {
        if(jsonObj[i]["MNGR_NAME"]) {
            count++;
        }
    }
    

    Working example: http://jsfiddle.net/j3fbQ/

提交回复
热议问题