如何从此JSON数组中提取值?

时间:2019-06-20 10:35:50

标签: java arrays json mapping

我有一个JSON数组。

{
    "calculateGoalAmount": [
        {
            "goalFrequency": "Monthly",
            "fromAccount": "0017a08d-3b3b-4a44-9e08-45e2cb8d4996",
            "goalAmount": 0.4166666667
        },
        {
            "goalFrequency": "Quarterly",
            "fromAccount": "0017a08d-3b3b-4a44-9e08-45e2cb8d4996",
            "goalAmount": 1.25
        }
    ]
}

如何获取此类JSON数组的值。这是我的示例代码。

public CalculateRecurringAmountResponseDTO mapRecurringAmount(RecurringAmountResponseDataDTO recurringAmountdataDTO) {

        //need to extract array first (recurringAMountdataDTO is the JSON array stated above)

        CalculateRecurringAmountResponseDTO recurringAmountMain = new CalculateRecurringAmountResponseDTO();
        if(recurringAmountdataDTO != null ) {

        RecurringAmountResponseDTO recurringAmountData = new RecurringAmountResponseDTO();

        for(RecurringAmountResponseDataDTO recurringAmountDBDTO : recurringAmountdataDTO) {
                recurringAmountData.setFromAccount(recurringAmountDBDTO.getFromAccount());
                recurringAmountData.setGoalAmount(recurringAmountDBDTO.getGoalAmount());
                recurringAmountData.setGoalFrequency(recurringAmountDBDTO.getGoalFrequency());
            }
            recurringAmountMain.setCalculatedGoalAmount(recurringAmountData);

        }

        return recurringAmountMain;
    }
}

需要映射到另一个DTO。如上所述。预先感谢。

0 个答案:

没有答案