1

SpringAndroid で RoboSpice を使用して JSON データを解析しています。ほとんどすべての JSON オブジェクトを取得できたにもかかわらず、メインの json オブジェクト内の json オブジェクトの内部配列リストを取得できませんでした。

これは、解析される結果の JSON の構造です。

{
  -Model[n]:
  -0:
     {
      name:"abcd"
      innerList[3]:
       {
         -0:
            {
             innerObject:
              {
               id:"10"
               .... 
              }
              .....
            }       
       }
     }
} 

innerObject の POJO でデータ メンバーにアクセスすると、null ポインター例外が発生します。

@JsonIgnoreProperties(ignoreUnknown = true)
public class Model{

 @JsonProperty("name")
 private String Name;

 @JsonProperty("innerList")
 private ArrayList<ClassInnerList> inner;

 //getters and setters
 }  

innerList の POJO:

 @JsonIgnoreProperties(ignoreUnknown = true)

 public class ClassInnerList
  {

   @JsonProperty("innerObject")
   ClassInnerObject innerObject;

   //getters and setters
   } 

Innerobject の POJO

@JsonIgnoreProperties(ignoreUnknown = true)

 public class ClassInnerObject{

  @JsonProperty("Id")
  String Id;

//getters and setters
   }

リクエストクラスは以下の通り

 public class GetDetailsRequest extends SpringAndroidSpiceRequest<Model> 
 {

   private String url;


     private Model Model;

      public GetDetailsRequest() {
      super(Model.class);

      this.url="my url"
      ...........

  }

@Override
  public Model loadDataFromNetwork() throws Exception {
    RestTemplate restTemplate=new RestTemplate();
    restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
    HttpHeaders httpHeaders=new HttpHeaders();
    httpHeaders.set("key","keyvalue");
    httpHeaders.setAccept(Collections.singletonList(new   MediaType("application","json)));
    HttpEntity<?> requestEntity = new HttpEntity<Object>(httpHeaders);
    ResponseEntity<Model> ResponseEntity=restTemplate.exchange(url, HttpMethod.GET,requestEntity,Model.class);
    Model=ResponseEntity.getBody();


    return Model;
}
}
4

0 に答える 0