Skip to content
Advertisement

Add contents of Array List to a JSON Array: Java

I have an Array List called getFields:

JavaScript

This array list logs out the following:

JavaScript

I need to convert getFields into a JSON Array called jsArray, so I have done this:

JavaScript

jsArray logs out the following:

JavaScript

The problem is, I do not want jsArray to have a nested array (i.e. I don’t want it to have double square brackets). I want it to be like this:

JavaScript

How can I convert getFields into jsArray without the double brackets? Have tried converting to a string but then I get backslashes. Any help would be appreciated. Thanks.

Advertisement

Answer

JavaScript

You need to iterate on getFields and put the elements one by one.


JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement