我有下面的输入JSON,我想在if条件中添加for循环
输入内容:
[
{
"sports": {
"percent": "10%",
"feeType": [
{
"discount": 12345,
"sport_fee_type": "Discounted fee",
"fee_details": [
{
"total": 1117.3,
"sports_catagory": "Cricket"
},
{
"total": 6187.79,
"sports_catagory": "Football"
}
]
},
{
"sport_fee_type": "Recurring fee",
"fee_details": [
{
"total": 1117.3,
"sports_catagory": "Cricket sport"
},
{
"total": 6187.79,
"sports_catagory": "Football"
}
]
},
{
"sport_fee_type": "Non Recurring fee",
"fee_details": [
{
"total": 1117.3,
"sports_catagory": "Cricket"
},
{
"total": 6187.79,
"sports_catagory": "football"
}
]
}
]
}
}
]
规格:
[
{
"operation": "shift",
"spec": {
"*": {
"@sports": {
"@percent": "additionalInfo[#1].value",
"#percent": "additionalInfo[#1].property",
"@feeType": {
"*": {
"sport_fee_type": {
"Discounted fee": {
"#discountAmount": "additionalInfo[&3].property",
"@2,discount": ["additionalInfo[&3].value", "discountedPrice"],
"@2,fee_details": {
"*": {
"total": ["billing.feeSummary[&5].sportsCategories[&1].amount"],
"sports_catagory": "billing.feeSummary[&5].sportsCategories[&1].sportType"
}
},
"#DISCOUNTED": "billing.feeSummary[#2].feeType"
},
"Non Recurring fee": {
"@2,fee_details": {
"*": {
"total": "billing.feeSummary[&5].sportsCategories[&1].amount",
"sports_catagory": "billing.feeSummary[&5].sportsCategories[&1].sportType"
}
},
"#NON_RECURRING": "billing.feeSummary[#4].feeType"
},
"Recurring fee": {
"@2,fee_details": {
"*": {
"total": "billing.feeSummary[&5].sportsCategories[&1].amount",
"sports_catagory": "billing.feeSummary[&5].sportsCategories[&1].sportType"
}
},
"#RECURRING": "billing.feeSummary[#4].feeType"
}
}
}
}
}
}
}
},
{ // convert the values of sportType attributes to uppercase
"operation": "modify-overwrite-beta",
"spec": {
"billing": {
"feeSummary": {
"*": {
"sportsCategories": {
"*": {
"sportType": "=toUpper"
}
}
}
}
}
}
},
{ // convert the values of sportType attributes to uppercase
"operation": "modify-overwrite-beta",
"spec": {
"billing": {
"feeSummary": {
"*": {
"sportsCategories": {
"*": {
"sportType": "=split(' ',@(1,&))"
}
}
}
}
}
}
},
{ // convert the values of sportType attributes to uppercase
"operation": "modify-overwrite-beta",
"spec": {
"billing": {
"feeSummary": {
"*": {
"sportsCategories": {
"*": {
"sportType": "=join('_',@(1,&))"
}
}
}
}
}
}
}
]
预期输出:
{
"additionalInfo": [
{
"value": "10%",
"property": "percent"
},
{
"property": "discountAmount",
"value": 12345
}
],
"discountedPrice": 12345,
"billing": {
"feeSummary": [
{
"sportsCategories": [
{
"amount": 1117.3,
"sportType": "CRICKET"
},
{
"amount": 6187.79,
"sportType": "FOOTBALL"
}
],
"feeType": "DISCOUNTED"
},
{
"sportsCategories": [
{
"amount": 1117.3,
"sportType": "CRICKET_SPORT"
},
{
"amount": 6187.79,
"sportType": "FOOTBALL"
}
],
"feeType": "RECURRING"
},
{
"sportsCategories": [
{
"amount": 1117.3,
"sportType": "CRICKET"
},
{
"amount": 6187.79,
"sportType": "FOOTBALL"
}
],
"feeType": "NON_RECURRING"
}
]
}
}
1条答案
按热度按时间ccrfmcuu1#
您可以考虑使用数组索引通过**[&5]和[&1]**标识符循环遍历它们,例如