2016-07-03 9 views
0

Ich versuche, ein Online-Wörterbuch mit der Verwendung von Free Dictionary API mit Hilfe von Retrofit Ich bin neu in Retrofit.Wenn ich die App laufen, die App der Absturz.Online-Wörterbuch api funktioniert nicht mit Retrofit

Logcat Fehler:

com.google.gson.stream.MalformedJsonException: Verwenden Sie JsonReader.setLenient (true) in Zeile 1 Spalte 1 Pfad $ 07-03 16 malformed JSON zu akzeptieren: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err: um com.google.gson.stream.JsonReader.syntaxError (JsonReader.java:1567) 07-03 16: 17: 38.531 25440- 25479/com.mohit.dictionaryapp W/System.err:
unter com.google.gson.stream.JsonR eader.checkLenient (JsonReader.java:1416) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err:
bei com.google.gson.stream.JsonReader.doPeek (JsonReader .java: 597) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err: um com.google.gson.stream.JsonReader.peek (JsonReader.java:429) 07 -03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err: um com.google.gson.internal.bind.CollectionTypeAdapterFactory $ Adapter.read (CollectionTypeAdapterFactory.java:74) 07- 03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err:
um com.google.gson.internal.bind.CollectionTypeAdapterFactory $ Adapter.read (CollectionTypeAdapt erFactory.java:61) 07-03 16: 17: 25.440 bis 25.479 38,531/com.mohit.dictionaryapp W/System.err:
bei retrofit2.converter.gson.GsonResponseBodyConverter.convert (GsonResponseBodyConverter.java:37) 07-03 16: 17: 25.440 bis 25.479 38,531/com.mohit.dictionaryapp W/System.err:
bei retrofit2.converter.gson.GsonResponseBodyConverter.convert (GsonResponseBodyConverter.java:25) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err:
bei retrofit2.ServiceMethod.toResponse (ServiceMethod.java:116) 07-03 16: 17: 38.531 25440-25479/com.mohit. dictionaryapp W/System.err: um retrofit2.OkHttpCall.parseResponse (OkH ttpCall.java:211) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err: um retrofit2.OkHttpCall.execute (OkHttpCall.java:174) 07-03 16:17 : 38,531 25.440-25.479/com.mohit.dictionaryapp W/System.err: bei retrofit2.ExecutorCallAdapterFactory $ ExecutorCallbackCall.execute (ExecutorCallAdapterFactory.java:89) 07-03 16: 17: 25.440 bis 25.479 38,531/com.mohit .dictionaryapp W/System.err:
um com.mohit.dictionaryapp.DictionaryApi.searchMeaning (DictionaryApi.java:33) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System. err:
um com.mohit.dictionaryapp.GetMeaningTask.doInBackground (GetMeaningTask.java:27) 07-03 16: 17: 25.440 bis 25.479 38,531/com.mohit.dictionaryapp W/System.err:
bei com.mohit.dictionaryapp.GetMeaningTask.doInBackground (GetMeaningTask.java:13) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err:
bei android.os.AsyncTask $ 2.aufruf (AsyncTask.java:288) 07-03 16: 17: 38.531 25440-25479/com .mohit.dictionaryapp W/System.err: um java.util.concurrent.FutureTask.run (FutureTask.java: 237) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err: um android.os.AsyncTask $ SerialExecutor $ 1.run (AsyncTask.java:231) 07-03 16: 17: 38.531 25440-25479/com.mohit.dictionaryapp W/System.err: um java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1112) 07-03 16: 17: 38.532 25440- 25479/com.mohit.dictionaryapp W/System.err:
um java.util.concurrent.ThreadPoolExecutor $ Worker.run (ThreadPoolExecutor.java:587) 07-03 16: 17: 38.532 25440-25479/com. mohit.dictionaryapp W/System.err:
bei java.lang.Thread.run (Thread.java:818)

DictionaryApi.java

public class DictionaryApi { 

    public interface Alfa{ 

     @GET("/word.json/{word}/definitions") 
     Call<ArrayList<Dictionary>> meaning(@Path("word") String word,@Query("api_key") String api_key); 
    } 

    public static ArrayList<Dictionary> searchMeaning(String word,String api_key){ 
     Retrofit retrofit=new Retrofit.Builder().baseUrl("http://api.wordnik.com/v4/") 
       .addConverterFactory(GsonConverterFactory.create()).build(); 
     Alfa alfa=retrofit.create(Alfa.class); 
     Call<ArrayList<Dictionary>> call = alfa.meaning(word,api_key); 
     try { 
      Response<ArrayList<Dictionary>> response=call.execute(); 
      Log.e("Dpi", response.message().toString()); 
      Log.e("Dpi",String.valueOf(response.code())); 
      return response.body(); 
     } catch (IOException e) { 
      e.printStackTrace(); 
      return null; 

     } 
    } 
} 

Dictionary.java (Pojo)

public class Dictionary { 
    public String word; 
    public String partOfSpeech; 
    public String sequence; 
    public String text; 
} 

Wörterbuch api url: http://api.wordnik.com/v4/word.json/fantasy/definitions?api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5

Bitte helfen Sie mir, diese zu lösen.

+0

Versuchen Sie, das "?" in der Anfrage. Retrofit verwaltet die Abfrageparameter. –

+0

Nopes, das hat nicht funktioniert ... habe ich auch versucht ... –

+0

Kannst du mir dein Retrofit-Debug-Log zeigen? –

Antwort

1

aus der Antwort JSON bekam von Ihrem api, versuchen Sie die pojo dem unten Wechsel -

public class Dictionary { 
    private List<Object> textProns = new ArrayList<Object>(); 
    private String sourceDictionary; 
    private List<Object> exampleUses = new ArrayList<Object>(); 
    private List<Object> relatedWords = new ArrayList<Object>(); 
    private List<Object> labels = new ArrayList<Object>(); 
    private List<Object> citations = new ArrayList<Object>(); 
    private String word; 
    private String partOfSpeech; 
    private String attributionText; 
    private String sequence; 
    private String text; 
    private Double score; 

    public List<Object> getTextProns() { 
    return textProns; 
    } 

    public void setTextProns(List<Object> textProns) { 
    this.textProns = textProns; 
    } 

    public String getSourceDictionary() { 
    return sourceDictionary; 
    } 

    public void setSourceDictionary(String sourceDictionary) { 
    this.sourceDictionary = sourceDictionary; 
    } 

    public List<Object> getExampleUses() { 
    return exampleUses; 
    } 

    public void setExampleUses(List<Object> exampleUses) { 
    this.exampleUses = exampleUses; 
    } 

    public List<Object> getRelatedWords() { 
    return relatedWords; 
    } 

    public void setRelatedWords(List<Object> relatedWords) { 
    this.relatedWords = relatedWords; 
    } 

    public List<Object> getLabels() { 
    return labels; 
    } 

    public void setLabels(List<Object> labels) { 
    this.labels = labels; 
    } 

    public List<Object> getCitations() { 
    return citations; 
    } 

    public void setCitations(List<Object> citations) { 
    this.citations = citations; 
    } 

    public String getWord() { 
    return word; 
    } 

    public void setWord(String word) { 
    this.word = word; 
    } 

    public String getPartOfSpeech() { 
    return partOfSpeech; 
    } 

    public void setPartOfSpeech(String partOfSpeech) { 
    this.partOfSpeech = partOfSpeech; 
    } 

    public String getAttributionText() { 
    return attributionText; 
    } 

    public void setAttributionText(String attributionText) { 
    this.attributionText = attributionText; 
    } 

    public String getSequence() { 
    return sequence; 
    } 

    public void setSequence(String sequence) { 
    this.sequence = sequence; 
    } 

    public String getText() { 
    return text; 
    } 

    public void setText(String text) { 
    this.text = text; 
    } 

    public Double getScore() { 
    return score; 
    } 

    public void setScore(Double score) { 
    this.score = score; 
    } 
} 

Theres ein großer Ort http://www.jsonschema2pojo.org/ aufgerufen, die u mit der Erzeugung von POJO der helfen kann.

+0

Danke, aber mein Problem ist aussortieren ... Die Lösung ist in den obigen Kommentaren .... –

+0

In Ordnung ... Ich dint sehen Sie Ihre Lösung, wenn Sie die Antwort posten. Mein Fehler! –