NutzCN Logo
问答 Json方法存在问题
发布于 1287天前 作者 lalala 1819 次浏览 复制 上一个帖子 下一个帖子
标签:

Json 字符串如下:

{"data":[{"created":1603336724000,"updated":1603336724000,"id":"10785697","fromImageId":"0","fromCidId":"10785696","imageData":"http://44.80.20.118/download/image/2020/10/22/2020-10-22-11-18-44-074-3357.jpg","xm":"cenzhizhi","score":0.0,"type":4,"cid":null,"realName":"","gender":"","time":1603336724000,"age":"-1"}],"errCode":0,"maxPage":0,"total":1,"count":0}

对象如下

public class IntelliUserRespVo {
    private List<IntellifUserAuthVo> data;
    private Integer errCode;
    private Integer maxPage;
    private Integer total;
    private Integer count;

    public List<IntellifUserAuthVo> getData() {
        return data;
    }

    public void setData(List<IntellifUserAuthVo> data) {
        this.data = data;
    }


...


public class IntellifUserAuthVo {

    @ApiModelProperty("姓名")
    private String xm;
    @ApiModelProperty("照片地址  暂不可访问")
    private String photo;
    @ApiModelProperty("照片Base")
    private String photoBase; // base64
    @ApiModelProperty("cid")
    private String fromCidId;
    @ApiModelProperty("手机号码,可能存在多个")
    private String sjhm;
    @ApiModelProperty("联系地址")
    private String dsmc;
    @ApiModelProperty("身份证")
    private String gmsfhm;
    @ApiModelProperty("民族名称")
    private String mzmc;


    public String getXm() {
        return xm;
    }

    public void setXm(String xm) {
        this.xm = xm;
    }

...

方法如下:

 IntelliUserRespVo respVo = Json.fromJson(IntelliUserRespVo.class, httpResponse.body());
        return respVo.getData().get(0).getFromCidId();

异常如下:

Exception in thread "main" java.lang.UnsupportedOperationException
	at java.util.AbstractCollection.add(AbstractCollection.java:262)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.injectCollection(ObjConvertImpl.java:192)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:85)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
	at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.injectObj(ObjConvertImpl.java:248)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:91)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
	at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
	at org.nutz.json.Json.parse(Json.java:94)
	at org.nutz.json.Json.fromJson(Json.java:73)
	at org.nutz.json.Json.fromJson(Json.java:178)

请问这个怎么处理呀

7 回复

List 用了java.awt.List ?

测试了一下, 并没有报错, 只是字段对不上, 很多数据丢了

确实是List对象引用错了,不过有一个新的问题

{"data":{"created":1603336724000,"updated":1603336724000,"id":"10785696","xm":"郭景祥","photo":"http://44.80.20.118/download/image/2020/10/22/2020-10-22-11-18-44-074-3357.jpg","dsmc":"北京大院79号","gmsfhm":"350054214141425","sjhm":"151454541,","cjsj":752083200000,"mzmc":"汉族"},"errCode":0,"maxPage":0,"total":0,"count":0}

        IntelliUserRespVo respVo = Json.fromJson(IntelliUserRespVo.class, httpResponse.body());


Exception in thread "main" org.nutz.castor.FailToCastObjectException: Fail to cast from <java.lang.Long> to <com.fjean.zzjj.service.intellif.IntellifUserAuthVo> for {1603336724000}
	at org.nutz.castor.Castors.cast(Castors.java:263)
	at org.nutz.castor.Castors.castTo(Castors.java:317)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.injectCollection(ObjConvertImpl.java:188)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:85)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
	at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.injectObj(ObjConvertImpl.java:248)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.inject(ObjConvertImpl.java:91)
	at org.nutz.mapl.impl.convert.ObjConvertImpl.convert(ObjConvertImpl.java:72)
	at org.nutz.mapl.Mapl.maplistToObj(Mapl.java:34)
	at org.nutz.json.Json.parse(Json.java:94)
	at org.nutz.json.Json.fromJson(Json.java:73)
	at org.nutz.json.Json.fromJson(Json.java:178)
	at com.fjean.zzjj.service.intellif.IntellifUserAuthService.getUserInfo(IntellifUserAuthService.java:65)
	at com.fjean.zzjj.service.intellif.IntellifUserAuthService.main(IntellifUserAuthService.java:163)
Caused by: org.nutz.lang.born.BorningException: Fail to born or cast to 'com.fjean.zzjj.service.intellif.IntellifUserAuthVo'
 by args: [@(1603336724000)]
 because: No suitable Constructor or Factory Method!!
	at org.nutz.lang.Mirror.born(Mirror.java:1020)
	at org.nutz.castor.castor.Object2Object.cast(Object2Object.java:12)
	at org.nutz.castor.Castors.cast(Castors.java:253)
	... 14 more


对象里面并没有使用created updated字段

数据都不一样, 之前data是List, 现在变成了对象

添加回复
请先登陆
回到顶部