JSON- string的对象数组转对象

public static void main(String[] args) {
        String str = "[{\"liveId\":8676034705,\"time\":1634622000,\"gmvAmt\":141120,\"watchCnt\":1075,"
                + "\"addFansCnt\":46,\"payItemCnt\":0,\"payBuyerCnt\":8,\"clickPayRatio\":0,\"perKWatchGmvAmt\":0,"
                + "\"watchAvgCnt\":139,\"orderCnt\":8}]";

        JSONArray jsonArray = JSONArray.fromObject(str);
        List<SellerLiveIndustryVO> collection =
                (List<SellerLiveIndustryVO>) JSONArray.toCollection(jsonArray, SellerLiveIndustryVO.class);
        log.info("querySellerIndustryRank.third.rpc.SellerLiveIndustryVO:{}", JSON.toJSONString(collection.get(0)));
    }


@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
public class SellerLiveIndustryVO implements Serializable {
    private Long liveId;
    private Long time;    //时刻
    private Long gmvAmt;    //累计成交金额
    private Long watchCnt;    //累计观看人数
    private Long addFansCnt;    //累计新增粉丝数
    private Long payItemCnt;    //累计成交件数
    private Long payBuyerCnt;    //累计成交人数
    private Long clickPayRatio;    //成交转换率
    private Long perKWatchGmvAmt;    //千次观看成交金额
    private Long watchAvgCnt;    //人均观看时长
    private Long orderCnt; //累计成交订单数
}

上一篇:Python中爬虫框架或模块的区别


下一篇:Java中将jsonArray导出为Excel