简体   繁体   中英

How to get the value of json object in jquery?

I have the following json:

{
    "Validation": {
    "status": "Validation:INITIATED",
    "subStatus": "Close:COMPLETED"
    },
    "Analysis": {
    "status": "Analysis:COMPLETED",
    "subStatus": "Close:COMPLETED"
    },
    "decomposition": {
    "status": "Decomposition:Inprogress",
    "subStatus": ""
    }
}

I need to get value of status and subStatus from the json. I have already tried the following:

$.each(dataStatus, function(key,value) {
    $.each(value,function(k,val){
       alert(val)
    })
});

But i don't get the desired output. Please suggest

What do you mean by "dynamically" ? You can access all the nodes and subnodes or just access a subStatus for exemple based on a variable ? For exemple :

dataStatus['Validation'].status

would return you the status of 'Validation'. You can have a variable instead of 'Validation', but it must be a string.

var myRecordName = 'Validation';
alert(dataStatus[myRecordName].status);

You can do the same for 'status' and 'substatus' of course...

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