从地图中删除一个键

时间:2017-07-21 18:57:55

标签: json groovy hashmap

以下json的类型为java.util.HashMap

<xsl:for-each select="$itemContent/item">
                <xsl:sort select="pub-date" order="descending"/>
                <xsl:if test="position() mod $group-size = 1">
                    <div class="item">
                        <xsl:if test="position()=1">
                            <xsl:attribute name="class">item active</xsl:attribute>
                        </xsl:if>
                        <ul>
                            <xsl:apply-templates select=".|following-sibling::item[position() &lt; $group-size]" mode="list"/>
                        </ul>
                    </div>
                </xsl:if>

            </xsl:for-each>

    <xsl:template match="item">
        <xsl:if test="position() mod $group-size = 1">
            <ul>
                <xsl:apply-templates select=".|/following::item[position() &lt; $group-size]" mode="list"/>
            </ul>
        </xsl:if>
    </xsl:template>

    <xsl:template match="item" mode="list">
        <li class="{position()}">
            <strong><a href="{url}"><xsl:value-of select="title" /> | <xsl:value-of select="position()" /></a></strong><br/>
            <xsl:value-of select="format-date(ou:get-xsdate(pub-date),'[FNn] [MNn] [D],  [Y]', 'en', (), ())" />
        </li>
    </xsl:template>

我试图在groovy中使用jsonRequest = jsonRequest.remove(“premiumList”)从下面的地图中删除premiumList。

当我打印jsonRequest时,它将输出显示为

jsonRequest=[noOfMembers:2, coverageYear:2017, zipCode:99123, premiumList:[[Premium:203.05, Id:1000101], [Premium:205.36, Id:1000102], [Premium:207.67, Id:1000103], [Premium:209.98, Id:1000104], [Premium:212.29, Id:1000105]], members:[[id:5487, age:34, gender:M], [id:5488, age:32, gender:F]]]

如何在groovy中从地图中删除整个premiumList?

1 个答案:

答案 0 :(得分:2)

即使您的java.util.HashMaphashmap并且您尝试删除密钥,也需要知道jsonRequest来自何处。 AFIK,你试图从请求中删除一个不允许删除的密钥?

def jsonRequest = [noOfMembers:2, coverageYear:2017, zipCode:99123, premiumList:[[Premium:203.05, Id:1000101], [Premium:205.36, Id:1000102], [Premium:207.67, Id:1000103], [Premium:209.98, Id:1000104], [Premium:212.29, Id:1000105]], members:[[id:5487, age:34, gender:M], [id:5488, age:32, gender:F]]]
​def output = [:] << jsonRequest

output.remove('premiumList')​