Arasu
Arasu

Reputation: 2148

Add values at the given position in a JSONArray

I'm using java, json.simple.JSONObject. I have a json object inside which I have a json array. I want to add empty values in a given postion

{"rows_map":{"2":["test1a","2011-12-08 18:13:50.6"],"1":["test2","2011-12-07 11:51:11.237"]}

Suppose i want to add values at second position

{"rows_map":{"2":["test1a","","2011-12-08 18:13:50.6"],"1":["test2","","2011-12-07 11:51:11.237"]}

How can I do this?

Upvotes: 2

Views: 2668

Answers (2)

Pratik
Pratik

Reputation: 30855

you can put the value by passing it's position for example

jsonarr.put(1,"");

check here for more http://www.json.org/javadoc/org/json/JSONArray.html

Upvotes: 2

Alnitak
Alnitak

Reputation: 339856

Just put the empty values into your array before you encode it!

Upvotes: 0

Related Questions