Member 13004006 Ответов: 0

Как получить данные из JSON arraylist только с определенными объектами также есть повторяющиеся значения


I have a Arraylist which i would be using to retrieve data but also there are multiple fields which are duplicates and after adding to hashmap it replaces the values.

Below is the arraylist and also output is mentioned below.

What would be the code which will provide the same output as given below.

Input:

[{AttributeValue=[{AttributeValue=2000.000000, AttributeName=accountBalance}, {AttributeValue=[{AttributeValue=51.200000, AttributeName=accountBalance}, {AttributeValue=146, AttributeName=dedicatedAccountID}, {AttributeValue=200.000000, AttributeName=accountBalance}, {AttributeValue=121, AttributeName=dedicatedAccountID}], AttributeName=dedicatedAccounts}, {AttributeValue=Offer HashMap, AttributeName=offers}, {AttributeValue=30, AttributeName=permanentServiceClass}, {AttributeValue=0, AttributeName=serviceOffering}], AttributeName=accountInformationAfterRefill}, {AttributeValue=[{AttributeValue=0.000000, AttributeName=accountBalance}, {AttributeValue=[{AttributeValue=10.000000, AttributeName=accountBalance}, {AttributeValue=121, AttributeName=dedicatedAccountID}], AttributeName=dedicatedAccounts}], AttributeName=accountInformationBeforeRefill}, {AttributeValue=30, AttributeName=currentServiceClass}, {AttributeValue=nftvtm5, AttributeName=originHostName}, {AttributeValue=EXT, AttributeName=originNodeType}, {AttributeValue=520541945, AttributeName=originTransactionID}, {AttributeValue=2384142050058, AttributeName=subscriberNumber}, {AttributeValue=2000.000000, AttributeName=transactionAmount}]

Output:

In Array list,

accountBalance = 2000.000000,permanentServiceClass = 30,accountBalance = 0.000000,currentServiceClass = 30,transactionAmount = 2000.000000

I had tried with hashmap but after that it replaces the accountBalance value. Then made other hashmap which will have only values but if i would do like this then have to create multiple hashmaps as the fields are not fixed. Is there anyway to get the output.


Что я уже пробовал:

if (tempMap.get("AttributeValue").getClass().isInstance(new String())) {
    String attribval = (String) tempMap.get("AttributeValue");
    String attribName = (String) tempMap.get("AttributeName");
    if (attribName.equalsIgnoreCase("accountBalance")) {
        newarray.add(attribval);
    } else {
        smVariable.put(tempMap.get("AttributeName"),
                tempMap.get("Att‌​ributeValue"));
    }
}

Richard MacCutchan

Вам нужно использовать другой тип списка, чтобы отфильтровать дубликаты по мере их чтения.

0 Ответов