top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How to convert a string into a JSON Array?

0 votes
470 views
How to convert a string into a JSON Array?
posted Jul 9, 2017 by Sumana

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

To convert a string into a JSON array, you need to create a JSONObject object for each of your objects, and add those to your JSON array.

Example

{
    "locations": [
        {
            "lat": "23.053",
            "long": "72.629",
            "location": "ABC",
            "address": "DEF",
            "city": "Ahmedabad",
            "state": "Gujrat",
            "phonenumber": "1234567"
        },
        {
            "lat": "23.053",
            "long": "72.629",
            "location": "ABC",
            "address": "DEF",
            "city": "Ahmedabad",
            "state": "Gujrat",
            "phonenumber": "1234567"
        }
    ]
}

Create a JSONObject object

JSONObject jsnobject = new JSONObject(readlocationFeed);

And after that write this

JSONArray jsonArray = jsnobject.getJSONArray("locations");
    for (int i = 0; i < jsonArray.length(); i++) {
        JSONObject explrObject = jsonArray.getJSONObject(i);
}
answer Jul 11, 2017 by Brajagopal Das
...