2016-03-06 67 views
1

我想使用改進來解析json到POJO,但不斷收到錯誤。 它似乎得到的數據,據我可以看到從logcat我讀取和正確解析json。但是它返回succes = false並且不返回一個responsedata對象。 錯誤類型和錯誤消息顯示爲空。 我不知道什麼是錯誤的,並會感謝解決方案或如何找到錯誤的任何建議。使用改進解析json到POJO

的Json

{ 
    "competition_info": { 
    "headline": "competition", 
    "description": "description for competition.", 
    "accept_button": "OK", 
    "open_terms_button": "Open info" 
    }, 
    "terms": { 
    "html": "a website in html" 
    } 
    } 

MyPojo

public class AnnComResponses{ 
    @SerializedName("competition_info") 
    public CompetitionInfo competitionInfo; 
    @SerializedName("terms") 
    public Terms terms; 

    public class Terms{ 

     @SerializedName("html") 
     public String html; 

     public String getTerms() { 
      return html; 
     } 
    } 

    public class CompetitionInfo{ 
     @SerializedName("headline") 
     public String headline; 
     @SerializedName("description") 
     public String description; 
     @SerializedName("accept_button") 
     public String acceptButton; 
     @SerializedName("open_terms_button") 
     public String openTermsButton; 

     public String getHeadline() { 
      return headline; 
     } 

     public String getDescription() { 
      return description; 
     } 

     public String getAcceptButton() { 
      return acceptButton; 
     } 

     public String getOpenTermsButton() { 
      return openTermsButton; 
     } 

    } 
} 
+0

請點擊此鏈接,它應該幫助 - http://stackoverflow.com/a/33720542/5123494 –

+0

嗨弗拉基米爾 我想我的問題表達不佳:-( 我 – MNielsen

回答

1

嘗試使用GSON轉換器,改進如下:

RestAdapter restAdapter = new RestAdapter.Builder() 
       .setLogLevel(RestAdapter.LogLevel.FULL) 
       .setConverter(new GsonConverter(new GsonBuilder()).create())) 
       .setEndpoint("your api end point goes here") 
       .build(); 
YourAPI api = restAdapter.create(YourAPI.class); 
+0

對不起,遲到的責任和thx你的幫助:-) – MNielsen

0

首先,你有幾類主類裏面。將它們分成單獨的文件並且不要將它們保存在同一個類中。其次,在您的主課程中,您需要爲您的屬性competitionInfo和條件添加setter和getters。此外,作爲一種良好的風格,這些屬性會保密,您的獲取者和設置者將保持公開。