0

I am having a problem with adding elements to JSON array iteratively using JADE Multi agent platform.
For example, the original JSON array was {["a","b","c]}. I want my result to be {["a","b","c","1","2"]}.
The JSOn Array element adding should be placed inside a cyclic behaviour.
I got something like this.

i=1
JSONArray array = new JSONArray();
JSONObject jsonObj = new JSONObject();
jsonObj.put("char",array);

addBehaviour(new TickerBehaviour(this,3000) {
array.add( i);
i++;
}

But the result was:

{["a","b","c","1"]}
{["a","b","c","2"]}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Anonymous
  • 3
  • 2

1 Answers1

0

If I understand correctly, you need to overwrite the previous object value with the updated one

array.add(i++);
jsonObj.put("char",array);
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245