Json org.json.Jsonexception error: Unterminated Object at Character

Asked

Viewed 735 times

3

I’m not finding the error at the time I catch this json

http://www.sinestandar.com.br/maker/sugeridos.txt

look what’s coming out in the log

12-19 13:39:53.589    9554-9564/json.exemplo.com.cortecabelo E/DEVMEDIA﹕ Erro no parsing do JSON
org.json.JSONException: Unterminated object at character 280 of { "AplicativosSugeridos" : [
{ "nome": "Chegou a Hora", "icone": "https://lh4.ggpht.com/IQ4km0WoDCIB-6ESZLzSYGYOae5X-ZDUKAdmB3D4_i7KF8HhVuWu65cpcxUOTDNH8tI=w300-rw" , "link": "https://play.google.com/store/apps/details?id=com.ilgner.chegouahora&hl=pt_BR },
{ "nome": "IMC Calc", "icone": "https://lh6.ggpht.com/VoNa54hKxdX6U47rrTlZ72ngPMFAcvTY38ugnifRsXSQJzAwprJDSZB25uBTHQoEbP8=w300-rw" , "link": "https://play.google.com/store/apps/details?id=com.ilgner.imc1&hl=pt_BR }
]
}
        at org.json.JSONTokener.syntaxError(JSONTokener.java:446)
        at org.json.JSONTokener.readObject(JSONTokener.java:390)
        at org.json.JSONTokener.nextValue(JSONTokener.java:96)
        at org.json.JSONTokener.readArray(JSONTokener.java:426)
        at org.json.JSONTokener.nextValue(JSONTokener.java:99)
        at org.json.JSONTokener.readObject(JSONTokener.java:381)
        at org.json.JSONTokener.nextValue(JSONTokener.java:96)
        at org.json.JSONObject.<init>(JSONObject.java:154)
        at org.json.JSONObject.<init>(JSONObject.java:171)
        at json.exemplo.com.cortecabelo.BaixarSugestoes.getSugestoes(BaixarSugestoes.java:70)
        at json.exemplo.com.cortecabelo.BaixarSugestoes.doInBackground(BaixarSugestoes.java:57)
        at json.exemplo.com.cortecabelo.BaixarSugestoes.doInBackground(BaixarSugestoes.java:27)
        at android.os.AsyncTask$2.call(AsyncTask.java:185)
        at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
        at java.lang.Thread.run(Thread.java:1019)

Code

@Override
protected List<Sugestoes> doInBackground(String... params) {
    String urlString = params[0];
    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(urlString);
    try {
        HttpResponse response = httpclient.execute(httpget);
        HttpEntity entity = response.getEntity();
        if (entity != null) {

            InputStream instream = entity.getContent();
            String json = toString(instream);
            instream.close();
            List<Sugestoes> sugestoes = getSugestoes(json);
            return sugestoes;
        }
    } catch (Exception e) {
        Log.e("DEVMEDIA", "Falha ao acessar Web service", e);
    }
    return null;
}

private List<Sugestoes> getSugestoes(String jsonString) {

    List<Sugestoes> sugestoes = new ArrayList<Sugestoes>();
    try {
        JSONObject trendLists = new JSONObject(jsonString);
        JSONArray jArray = trendLists.getJSONArray("AplicativosSugeridos");

        for (int i = 0; i < jArray.length(); i++) {
            Sugestoes sugestao = new Sugestoes();
            JSONObject json_data = jArray.getJSONObject(i);
            sugestao.nome = json_data.getString("nome");
            sugestao.link = json_data.getString("link");
            sugestao.icone = json_data.getString("icone");
            String nomeArquivo=baixarImagem(sugestao.icone, "imagemSugestao" + i);
            sugestao.icone = nomeArquivo;
            Banco banco = new Banco(context);
            if(banco.insertS(sugestao)){
                Log.d("Resultado S","Salvou");
            }else{
                Log.d("Resultado S","Nao Salvou");
            }
            sugestoes.add(sugestao);
        }

    } catch (JSONException e) {
        Log.e("DEVMEDIA", "Erro no parsing do JSON", e);
    } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    return sugestoes;
}
  • 2

    Your Urls inside the objects are without quotation marks

1 answer

2


Your second link is not closed as a string.

"nome": "Chegou a Hora",
"icone":
"https://lh4.ggpht.com/IQ4km0WoDCIB-6ESZLzSYGYOae5X-ZDUKAdmB3D4_i7KF8HhVuWu65cpcxUOTDNH8tI=w300-rw",
"link":
"https://play.google.com/store/apps/details?id=com.ilgner.chegouahora&hl=pt_BR  <- Cade o fechamento das aspas!?
  • 1

    in that stupid kkkk , thank you nor had seen

  • It’s not stupid, in a hurry, you forget one thing or another and keep thinking "what the hell is going wrong? It’s all right!". I happened to send a JSON with a list to fill a table. One job, she was right, but the other one wasn’t, and I didn’t understand why. Until I saw that what the table was getting was not a list... haha

  • 1

    and kk , was crazy here because I used the same code to recover other json was here looking what was wrong kk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.