Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Android i JSON citanje podataka sa linka

[es] :: Java :: Android i JSON citanje podataka sa linka

[ Pregleda: 1472 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

normandija
Srbija

Član broj: 70439
Poruke: 364
*.lewilew.com.



+62 Profil

icon Android i JSON citanje podataka sa linka20.10.2012. u 18:24 - pre 140 meseci
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();

Bolje izgubiti trenutak u zivotu,nego zivot u trenutku !!!
 
Odgovor na temu

bantu

Član broj: 38670
Poruke: 305
89.111.240.*



+27 Profil

icon Re: Android i JSON citanje podataka sa linka22.10.2012. u 07:10 - pre 140 meseci
Napravi ulazni string ovako: [{"test":"hello world"}] pa ce da ti bude array, inace je object.
 
Odgovor na temu

normandija
Srbija

Član broj: 70439
Poruke: 364
*.lewilew.com.



+62 Profil

icon Re: Android i JSON citanje podataka sa linka22.10.2012. u 09:57 - pre 140 meseci
E hvala mnogo,sada radi sve :)
Bolje izgubiti trenutak u zivotu,nego zivot u trenutku !!!
 
Odgovor na temu

[es] :: Java :: Android i JSON citanje podataka sa linka

[ Pregleda: 1472 | Odgovora: 2 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.