Possible duplicate:
JSON parsing problem
I am parsing a JSON file (which is valid). It works on Android 4.0 - 4.0.4, but not on older versions of Android. This is part of my manifest:
<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="14" />
And this is my syntax code:
public JSONObject getJSONFromUrl(String url) { try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpResponse.getEntity(); is = httpEntity.getContent(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } try { BufferedReader reader = new BufferedReader(new InputStreamReader( is, "UTF-8"), 8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); json = sb.toString(); } catch (Exception e) { Log.e("Buffer Error", "Error converting result " + e.toString()); } try { jObj = new JSONObject(json); } catch (JSONException e) { Log.e("JSON Parser", "Error parsing data " + e.toString()); } return jObj; }
And on older devices, the following error message appears (But, as I said, on new Android devices):
org.json.JSONException: value of type java.lang.String cannot be converted to JSONObject
I have absolutely no idea why it works on Android 4, but not on older devices.
Find Json from here
source share