2015-09-02 67 views
0

我在主類中有objectList。我正在使用Jackson的SimpleBeanPropertyFilter.filterOutAllExcept,但我沒有得到過濾的響應。任何人都可以幫助我,JSON響應如下。Filter使用Jackson's BeanPropertyFilter的對象列表

{ 
    "person": [ 
      { 
     "firstName": "Shyam", 
     "age": 7, 
     "addressDetails":   [ 
         { 
       "houseNo": "1236", 
       "buildingNo": "T4", 
       "address1": "sector 34", 
       "address2": "near hospital", 
       "city": "noida", 
       "state": "UP", 
       "pinCode": 1400021 
      }, 
         { 
       "houseNo": "1236", 
       "buildingNo": "T4", 
       "address1": "sector 34", 
       "address2": "near hospital", 
       "city": "noida", 
       "state": "UP", 
       "pinCode": 1400021 
      } 
     ], 
     "lastName": "singh" 
     } 
    ], 
    "syncDate": 1441167154507, 
    "nextPage": "http://localhost:8080/personData/Date=1437458428657" 
} 
+0

什麼是您的過濾器的代碼是什麼樣子? – usandfriends

回答

0

試試這個,有使用兩個環路1號,因爲我用它來獲得人數組數據,其他對於j使用獲得的地址相關內容。

try { 
     JSONObject responseJsonObject = new JSONObject(response); 
     String syncDate=responseJsonObject.getString("syncDate"); 
     String nextPage=responseJsonObject.getString("nextPage"); 

     JSONArray jsonPerson_jsonarray = responseJsonObject 
       .getJSONArray("person"); 
     Log.i("get_array", jsonPerson_jsonarray + ""); 
     for (int i = 0; i < jsonPerson_jsonarray.length(); i++) { 
      JSONObject personDetail = jsonPerson_jsonarray 
        .getJSONObject(i); 

      String firstName=personDetail.getString("firstName"); 
      String age=personDetail.getString("age"); 
      String lastName=personDetail.getString("lastName"); 
      JSONArray addressDetails_jsonarray = personDetail 
        .getJSONArray("addressDetails"); 

      for (int j = 0; j < addressDetails_jsonarray.length(); j++) { 
       JSONObject addressDetails = addressDetails_jsonarray 
         .getJSONObject(j); 

       String houseNo=addressDetails.getString("houseNo"); 
       String buildingNo=addressDetails.getString("buildingNo"); 
       String address1=addressDetails.getString("address1"); 
       String address2=addressDetails.getString("address2"); 
       String city=addressDetails.getString("city"); 
       String state=addressDetails.getString("state"); 
       String pinCode=addressDetails.getString("pinCode"); 
      } 

     } 
    } catch (JSONException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

替換與bean類的getter setter方法循環字符串或使用數組,並獲得所需的數據

+0

謝謝,但我能夠解析的迴應。但問題是我需要將部分Json響應發送給客戶端。根據url參數中提供的字段詳細信息。 – singh