my app was working really nice with that json
{
"id":"1",
"title_en":"Civil War",
"artist_en":"MOTORHEAD"
}
but when i tried to add multiple songs like that
{
"song_list":[
{"id":"1",
"title_en":"Civil War",
"artist_en":"MOTORHEAD"},
{"id":"2",
"title_en":"Slide It In",
"artist_en":"WHITESNAKE"}]
}
it generates an exception, even before retrieving data
09-08 07:29:53.998: W/System.err(982): org.json.JSONException: Value ? of type java.lang.String cannot be converted to JSONObject
09-08 07:29:53.998: W/System.err(982): at org.json.JSON.typeMismatch(JSON.java:107)
09-08 07:29:53.998: W/System.err(982): at org.json.JSONObject.<init>(JSONObject.java:158)
09-08 07:29:53.998: W/System.err(982): at org.json.JSONObject.<init>(JSONObject.java:171)
09-08 07:29:53.998: W/System.err(982): at com.dwaik.jsonparser.JSONParser.getJSONObject(JSONParser.java:46)
09-08 07:29:53.998: W/System.err(982): at com.dwaik.myapp.CustomizedListView.onCreate(CustomizedListView.java:48)
additional info : the parser
public JSONObject getJSONObject(InputStream inputStream)
{
String result = null;
JSONObject jObject = null;
try
{
// json is UTF-8 by default
BufferedReader reader;
reader = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
sb.append(line + "\n");
result = sb.toString();
jObject = new JSONObject(result);
}
catch (JSONException e)
{
e.printStackTrace();
return null;
}
catch (IOException e)
{
e.printStackTrace();
return null;
}
finally
{
try
{
if (inputStream != null)
inputStream.close();
}
catch (Exception e)
{
}
}
return jObject;
}
and its call
final JSONObject jObject = (new JSONParser(this)).getJSONObject(getResources().openRawResource(R.raw.sample));