So fügen Sie JsonArray Objekt hinzuJava

Java-Forum
Anonymous
 So fügen Sie JsonArray Objekt hinzu

Post by Anonymous »

Ich möchte einem Array ein Objekt hinzufügen. Wenn die Daten von Other_Amount mehr als Null sind, möchte ich ein Objekt mehr hinzufügen. Wenn es gleich Null ist, sollte es nichts hinzufügen. Dies ist mein Code: < /p>

JSONArray acc_data = new JSONArray();
Map myaccount = new LinkedHashMap();
for (int i = 0; i < mpay.size(); i++) {
if(other_amount>0){
myaccount.put("poAccount", other_account);
myaccount.put("poAmount", other_amount);
system.out.println(myaccount);
//{poAccount=050017, poAmount=12}
}

myaccount.put("poAccount", amount_account);
myaccount.put("poAmount", amount);
system.out.println(myaccount);
//{"poAccount":"050016","poAmount":"800"}

acc_data.add(myaccount);
system.out.println(acc_data);
//[{"poAccount":"050016","poAmount":"800"}]
}
< /code>

Aber ich brauche es so: < /p>

//[{"poAccount":"050016","poAmount":"800"},{poAccount=050017, poAmount=12}]
< /code>

Bitte helfen Sie mir, es zu beheben. < /p>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post