[ normandija @ 20.10.2012. 18:24 ] @
Pozdrav, da li mi neko moze reci gde gresim, pokusavam da iz android aplikacije procitam jedan JSON podatak,ali mi stalno baca sledecu gresku org.json.JSONException: Value {"test":"hello world"} of type org.json.JSONObject cannot be converted to JSONArray. pikne na lini koda JSONArray jArray = new JSONArray(result); kad treba da smesti rezultat koji dobijem kroz response a evo i koda: Code: new Thread(new Runnable() { public void run(){ try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("http://traveliusa.pl/api/test/test"); //httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); } catch(ClientProtocolException ex) { Log.i("ERROR", "Error in connetion with server!" +ex.getMessage()); } catch(IOException ex) { Log.i("ERROR", "2Error in connetion with server!" +ex.getMessage()); } try { BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null){ sb.append(line + "\n"); } is.close(); result=sb.toString(); } catch(Exception ex) { Log.i("ERROR", "Error reading server response!" +ex.getMessage()); } // Parse the JSON data. try { JSONArray jArray = new JSONArray(result); for(int i=0;i<jArray.length();i++) { JSONObject json_data = jArray.getJSONObject(i); String tt = json_data.getString("test"); Log.i("INFO", json_data.getString("test")); } } catch(JSONException ex) { Log.i("ERROR", "Error parsing JSON data!" +ex.getMessage()); } } }).start(); |