No serializer found for class org.json.JSONObject and no properties discovered to create BeanSerializer

后端 未结 1 1145
悲&欢浪女
悲&欢浪女 2020-12-06 11:43

having JSON from web service, Json Array as a response

   [3]
   0:  {
   id: 2
  name: \"a561137\"
    password: \"test\"
  firstName: \"abhishek\"
   last         


        
相关标签:
1条回答
  • 2020-12-06 12:15

    have To Accept it first as a Json Array ,then while reading its Object have to use Object Mapper.readValue ,because Json Object Still in String .

    List<User> list = new ArrayList<User>();
    JSONArray jsonArr = new JSONArray(response);
    
    for (int i = 0; i < jsonArr.length(); i++) {
        JSONObject jsonObj = jsonArr.getJSONObject(i);
        ObjectMapper mapper = new ObjectMapper();
        User usr = mapper.readValue(jsonObj.toString(), User.class);      
        list.add(usr);
    }
    
    0 讨论(0)
提交回复
热议问题