如何将json响应存储在数组中并对其进行排序

时间:2015-09-02 14:26:26

标签: json string groovy formatter

我想将值关系id,relationshipType存储在数组中,排序然后在Groovy中打印该数组。 到目前为止我有这个......

def slurper = new JsonSlurper()
def result = slurper.parseText(reponse)

{"RecipientRelationships": [
      {
      "RelationshipId": "15",
      "RelationshipType": "Self"
   },
      {
      "RelationshipId": "1",
      "RelationshipType": "Mother"
   },
      {
      "RelationshipId": "2",
      "RelationshipType": "Father"
   },

2 个答案:

答案 0 :(得分:0)

喜欢这个吗?

import groovy.json.JsonSlurper

def response = '''{"RecipientRelationships": [
        {
            "RelationshipId": "15",
            "RelationshipType": "Self"
        },
        {
            "RelationshipId": "1",
            "RelationshipType": "Mother"
        },
        {
            "RelationshipId": "2",
            "RelationshipType": "Father"
        }]
}'''
JsonSlurper slurper = new JsonSlurper()
Map result = slurper.parseText(response)
result.RecipientRelationships.sort {
    it.RelationshipId as Integer
}.each {
    println it
}

答案 1 :(得分:0)

#main {
    margin: auto;
    width: 300px;
    display: flex; /*added*/
}

.image {
    background-image: url(http://www.todopuertas.net/images/conoce.png);
    height: 100px;
    right: 0;
    bottom: 0;
    background-size: contain;
    background-repeat: no-repeat;
    background-position-y: 100%;  /*added to bottom align the img*/
}

.column1 {
    float: left;
    width: 100px;
    position: relative;
    align-self: flex-end; /*added to aligned to bottom*/
    border: 1px solid; /*to show that is aligned*/
}

.column2 {
    float: right;
    right: 0;
    width: 150px;
    position: relative;
    background-color: #FFFF00;
}