• groovy 从jsonList中读取某个字段


    今天又被groovy的高效吓到了。

    想提取所有的itemCodes,两种玩法

    一、常规方法:遍历组装

    RestResult items = getListPager()
    def temp = []
    items.data.data.each {
         temp.push(it.itemCode)
    }
    println(temp)

    [DP180929155952858, DP180511114211610, DP1539683378800, DP1539682576227, DP1539681917164, DP1539681882632, DP1539681460929, DP1539681297697, DP1539679354755]

    二、直接拿值,简直不能再高效了

    RestResult items = getListPager()
    def itemCodes = items.data.data.itemCode
    println(itemCodes)

    [DP180929155952858, DP180511114211610, DP1539683378800, DP1539682576227, DP1539681917164, DP1539681882632, DP1539681460929, DP1539681297697, DP1539679354755]

    {
      "code" : "ok",
      "data" : {
        "data" : [ {
          "itemCode" : "DP180929155952858",
          "itemName" : "成本测试专用-勿动",
          "itemType" : "SINGLE",
          "itemTypeName" : "单品",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP180511114211610",
          "itemName" : "百事",
          "itemType" : "SINGLE",
          "itemTypeName" : "单品",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539683378800",
          "itemName" : "自动合成品20181016164446",
          "itemType" : "MATERIAL",
          "itemTypeName" : "原材料",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539682576227",
          "itemName" : "自动合成品20181016164446",
          "itemType" : "MATERIAL",
          "itemTypeName" : "原材料",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539681917164",
          "itemName" : "自动合成品20181016164446",
          "itemType" : "MATERIAL",
          "itemTypeName" : "原材料",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539681882632",
          "itemName" : "自动合成品20181016164446",
          "itemType" : "MATERIAL",
          "itemTypeName" : "原材料",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539681460929",
          "itemName" : "自动单品20181016171741",
          "itemType" : "SINGLE",
          "itemTypeName" : "单品",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539681297697",
          "itemName" : "自动单品20181016171457",
          "itemType" : "SINGLE",
          "itemTypeName" : "单品",
          "purchaseSpecName" : "箱",
          "tax" : 1
        }, {
          "itemCode" : "DP1539679354755",
          "itemName" : "自动原材料20181016164234",
          "itemType" : "MATERIAL",
          "itemTypeName" : "原材料",
          "purchaseSpecName" : "箱",
          "tax" : 8
        } ],
        "page" : {
          "endPage" : 19,
          "offset" : 0,
          "pageNo" : 1,
          "pageSize" : 20,
          "totalPage" : 1,
          "totalRecord" : 9
        }
      },
      "message" : "成功"
    }
  • 相关阅读:
    configure: error: HTSlib development files not found
    configure: error: htscodecs submodule files not present.
    如何给虚拟机的磁盘动态扩容
    关闭anaconda3 默认自动启动的命令
    github.com[0: 192.30.255.113]: errno=Connection refused
    centos7 中安装java8
    centos7 中manta软件的安装
    168张图,万字长文,手把手教你开发vue后台管理系统
    maven打包excel乱码
    面渣逆袭:Java集合连环三十问
  • 原文地址:https://www.cnblogs.com/dannyyao/p/9804193.html
Copyright © 2020-2023  润新知