How Can I parse a JSON ARRAY to get the data without the [] and ""
here is the json
"formattedAddress": [
"23, Damansara - Puchong Hwy (Bandar Puchong Jaya)",
"47100 Puchong Batu Dua Belas, Selangor",
"Malaysia"
]
my code:
poi.setFormattedAddress(jsonArray.getJSONObject(i).getJSONObject("location").getJSONArray("formattedAddress").toString());
output: [ "23, Damansara - Puchong Hwy (Bandar Puchong Jaya)", "47100 Puchong Batu Dua Belas, Selangor", "Malaysia" ]
I just want the data. as:
23, Damansara - Puchong Hwy (Bandar Puchong Jaya), 47100 Puchong Batu Dua Belas, Selangor, Malaysia
Thanks
Use
JSONArray#join()
to join the elements. Check out the JSONArray docs for more info.It's unclear if the quotations are part of your input JSON string. If they show up in your join, you can easily remove them with the
String#replace()
method.Try something like this:
Use JSONArray.join():