2016-03-06 65 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。此外,作为一种良好的风格,这些属性会保密,您的获取者和设置者将保持公开。