muhammad zeeshan muhammad zeeshan - 6 months ago 28
Java Question

How to read this array in android from arraylist

Hey i have this array which my array list is generating

id= 197,
title=example Water 320ML Bottle (Pack of 24) For 6 Months, price=238.50

but how read this array i tried

JSONObject jsonRootObject = new JSONObject(createArray);
JSONObject data = jsonRootObject.getJSONObject("image");

but it gives me error

org.json.JSONException: Unterminated object at character 21 of {id= 197, image=, category=, title=VOLO example 320ML Bottle (Pack of 24) For 6 Months, price=238.50}


Just add doable QUOTE "" marks to your XML

<?xml version="1.0" encoding="UTF-8"?> <music> <song> <id>198</id> <title>"Eample Water 320ML Bottle (Pack of 24) For 12 Months"</title> <price>225.20</price> <desc /> <image>""
 <category>"test"</category> </song> </music>

then read it like this

JSONObject jsonRootObject = new JSONObject(createArray);

String data = jsonRootObject.getString("id");

System.out.println("The data "+data);