-2

I'm fetching 6 items from json. But I also want to add manually some items.

For example like this: https://image.ibb.co/cUvEuJ/main_qimg_432fcb81bdce8f7e9c42d4cf4a7b2acf.jpg

Thanks a lot.

2 Answers2

0

I found this solution for javascript:

var jsonArray1 = [{'name': "doug", 'id':5}, {'name': "dofug", 'id':23}];

var jsonArray2 = [{'name': "goud", 'id':1}, {'name': "doaaug", 'id':52}];

jsonArray1 = jsonArray1.concat(jsonArray2);

// jsonArray1 = [{'name': "doug", 'id':5}, {'name': "dofug", 'id':23}, //{'name': "goud", 'id':1}, {'name': "doaaug", 'id':52}];

For java:

Concat two json objects in java

0

you can use put() method in JSONArray

// parser class to parser the string
JSONArray array = Parser.parse(jsonString);
// adding manually some items
array.put("some string");
//adding some boolean
array.put(false);
//add some integer
array.put(10);
//add some JSONObject
JSONObject obj = new JSONObject()
obj.put("key","value");
array.put(obj)

so you can create jsonObject or java basic variable types and add them manually to jsonArray

Shayan D
  • 620
  • 3
  • 14