I wasted a long time in the process of data parsing. At first I always thought that the type of the object that was passed on was json, so I thought about that method. It took a long time to do it.
Later, I read what someone wrote and found out that it was really simple. Thanks to /p/d0081e8a7edc for inspiring me.
Added jar package
// Retrofit library
implementation '.retrofit2:retrofit:2.0.2'
implementation '.retrofit2:converter-gson:2.0.2'
Data transmitted from the server:
{
"code":0,
"resultMsg":"OJBK",
"resultState":"SUCCESS",
"resultObj":[
{"id":null,"nickname":"Koke","head_img":null,},
{"id":null,"nickname":"Koke","head_img":null,},
{"id":null,"nickname":"Koke","head_img":null,},
{"id":null,"nickname":"Koke","head_img":null,},
{"id":null,"nickname":"Li Kui","head_img":"",}]}
Create a WebResponse object to receive data:
package .; import ; import ..HNOTICELOG_E; public class WebRespone { /** * Return status code */ private Integer code; /** * Return message */ private Object resultMsg; /** * Return result */ private String resultState; /** * Return the data object */ private List<HNOTICELOG_E> resultObj; public Integer getCode() { return code; } public Object getResultMsg() { return resultMsg; } public String getResultState() { return resultState; } public void setCode(Integer code) { = code; } public void setResultMsg(Object resultMsg) { = resultMsg; } public void setResultState(String resultState) { = resultState; } public List<HNOTICELOG_E> getResultObj() { return resultObj; } public void setResultObj(List<HNOTICELOG_E> resultObj) { = resultObj; } }
Note that one of the objects is of list type.
public class HNOTICELOG_E { private Long id; private String nickname; private String head_img; private String noticeContext; private String relUserId; private String relNoticeUserId; private Date createTime; private String createUser; private Date updateTime; private String updateUser; private Integer status; public Long getId() { return id; } public void setId(Long id) { = id; } public String getNoticeContext() { return noticeContext; } public void setNoticeContext(String noticeContext) { = noticeContext == null ? null : (); } public String getRelUserId() { return relUserId; } public void setRelUserId(String relUserId) { = relUserId == null ? null : (); } public String getRelNoticeUserId() { return relNoticeUserId; } public void setRelNoticeUserId(String relNoticeUserId) { = relNoticeUserId == null ? null : (); } public Date getCreateTime() { return createTime; } public void setCreateTime(Date createTime) { = createTime; } public String getCreateUser() { return createUser; } public void setCreateUser(String createUser) { = createUser == null ? null : (); } public Date getUpdateTime() { return updateTime; } public void setUpdateTime(Date updateTime) { = updateTime; } public String getUpdateUser() { return updateUser; } public void setUpdateUser(String updateUser) { = updateUser == null ? null : (); } public Integer getStatus() { return status; } public void setStatus(Integer status) { = status; } public String getNickname() { return nickname; } public void setNickname(String nickname) { = nickname; } public String getHead_img() { return head_img; } public void setHead_img(String head_img) { this.head_img = head_img; } }
It is equivalent to the resultObj below which is directly a List. In this way, you can directly receive the List object in the json transmitted by the server.
The above is all the content of this article. I hope it will be helpful to everyone's study and I hope everyone will support me more.