I have been struggling with this for hours, what am I doing wrong.
I am trying to parse data from this API using org.json library.
JSONParser jsonParser = new JSONParser();
JSONObject obj = (JSONObject) jsonParser.parse(getAllCustomers());
JSONArray arr = obj.getJSONArray("data");
for (int i = 0; i < arr.length(); i++) {
String name = arr.getJSONObject(i).getString("name");
}
I dont even know if my code is correct, but I get an error saying that .getJSONArray() cannot find symbol, same with .getJSONObject.
What am I doing wrong here.
JSON:
"data": [
{
"id": 1,
"name": "Bitcoin",
"symbol": "BTC",
"website_slug": "bitcoin"
},
{
"id": 2,
"name": "Litecoin",
"symbol": "LTC",
"website_slug": "litecoin"
},
{
"id": 3,
"name": "Namecoin",
"symbol": "NMC",
"website_slug": "namecoin"
},
{
"id": 4,
"name": "Terracoin",
"symbol": "TRC",
"website_slug": "terracoin"
},
{
"id": 5,
"name": "Peercoin",
"symbol": "PPC",
"website_slug": "peercoin"
},
{
"id": 6,
"name": "Novacoin",
"symbol": "NVC",
"website_slug": "novacoin"
},
{
"id": 8,
"name": "Feathercoin",
"symbol": "FTC",
"website_slug": "feathercoin"
},
{
"id": 9,
"name": "Mincoin",
"symbol": "MNC",
"website_slug": "mincoin"
},
}
EDIT changed from "posts" to "data". Still issues with the above methods
posts