So fügen Sie JsonArray Objekt hinzu

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: So fügen Sie JsonArray Objekt hinzu

by Anonymous » 12 Feb 2025, 13:07

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>

Top