以下是我的json
{
"corpAPIBankingReq": {
"Header": {
"TranID": "1"
},
"Body": {
"CustType": "Corporate",
"Action_Type": "MultiPayment",
"Action_Body": {
"doMultiPaymentCorpReq": {
"Header": {
"TranID": "${=System.currentTimeMillis() + ((int)(Math.random()*1000))}",
"Corp_ID": "ZOHO",
"Maker_ID": "M001",
"Checker_ID": "C001",
"Approver_ID": "A002"
},
"Body": {
"Payment": [
{
"RefNo": "test1",
"Amount": "100",
"Debit_TrnParticulars": "AISHWARYA",
"Debit_PartTrnRmks": "SESHADRI",
"Ben_Acct_No": "1000110010002463",
"Ben_TrnParticulars": "FTTEST",
"Ben_PartTrnRmks": "ABHIJEET",
"Mode_of_Pay": "FT",
"Nature_of_Pay": "SALC",
"Remarks": "DMR"
},
{
"RefNo": "test10063",
"Amount": "5",
"Debit_Acct_No": "409000115190",
"Debit_Acct_Name": "SACHIN R TENDULKAR",
"Debit_IFSC": "RATN0000999",
"Debit_Mobile": "9819378393",
"Ben_IFSC": "UBIN0556688",
"Ben_Acct_No": "8884476527",
"Ben_Name": "Sudarshan",
"Ben_BankName": "DHANALAXMI-Bank",
"Ben_Email": "prabhat.deep1234567wearethebest@naturesports.co.in",
"Ben_Mobile": "9696969696",
"Mode_of_Pay": "IMPS",
"Nature_of_Pay": "MPYMT",
"Remarks": "IMPS REQUEST"
}
]
},
"Signature": {
"Signature": "1234"
}
}
}
}
}
}
在上面的json中,我需要找出“Action_Body”的第一个孩子,在这种情况下是“doMultiPaymentCorpReq”。这个键会继续动态变化,所以我需要从它的父节点中找到它。然后我会像
一样使用它if(first child of Action Body is doMultiPaymentCorpReq){
Do something;
}
else{
Do something else;
}
有人可以帮助我如何在这里找到第一个元素。提前谢谢。
答案 0 :(得分:0)
如果您想在first item
中找到Action_Body
的{{1}}并比较值:
JSON
for (first in obj.corpAPIBankingReq.Body.Action_Body) {
if (first == 'doMultiPaymentCorpReq') {
console.log('yes');
} else {
console.log('no');
}
}