We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
比如我的数据类型是这样的:
{"data":[ { "created_at":"Sat May 14 22:05:52 +0800 2022", "id": "4769148843065803", "disable_reply": 0, "comments":[ { "created_at":"Sat May 14 22:09:52 +0800 2022", "id": "4769148843065805", "disable_reply": 1, "comments":[] }, { "created_at":"Sat May 14 22:20:52 +0800 2022", "id": "4769148843065807", "disable_reply": 4, "comments":[] } ] }, { "省略":"省略" } ] }
我尝试建一个映射类去接收:
import java.util.List; @Data public class Comment { //评论时间 private String created_at; // 省略部分字段....... // 该条评论下的评论 private List<Comment> comments; }
我的接收处理:
List<Comment> cts= data.getArray("data").toList(Comment.class);
目前无法接收,会报如下错误:
The text was updated successfully, but these errors were encountered:
对象 Array 的 toList() 方法当前只支持简单的对象,还不支持对象中内嵌 List 的情况,这将在下个版本中增强它。
Array
toList()
List
但是这个情况可以这么用,定义一个通用的结果类:
public class Result<T> { private T data; // 省略 Getter Setter }
然后请求的时候:
// 使用复合泛型 Result<List<Comment>>> result = OkHttps.sync("/xxx").get().getBody() .toBean(new TypeRef<Result<List<Comment>>>{}); // 得到 List<Comment> List<Comment> comments = result.getData();
Sorry, something went wrong.
你好,我自己尝试研究了一下,还是没接收到
你多写了一步,是 getBody() 后就 toBean(), 不需要先 toMapper()
你多写了一步,是 getBody() 后就 toBean(), 不需要先 toMapper() 也报错了
No branches or pull requests
比如我的数据类型是这样的:
我尝试建一个映射类去接收:
我的接收处理:
目前无法接收,会报如下错误:
The text was updated successfully, but these errors were encountered: