Jsonpath排序数组

时间:2016-07-01 15:01:59

标签: sorting soapui jsonpath

请你能帮我排序我使用$ .. balanceChange得到的数组。这只是回应的一小部分。

我需要它来在SoapUI中进行断言。

 {
      "id": 182,
      "name": "49899 Consol Sick w S&S Pattern",
      "eventDefinition":       {
         "id": 111,
         "name": "49899 Consol Sick w S&S Pattern",
         "shortName": null,
         "displayName": "49899 Consol Sick w S&S Pattern",
         "active": true,
         "group": null,
         "lowerThresholdAmount": 0,
         "upperThresholdAmount": 0,
         "lowerThresholdDayAmount": null,
         "upperThresholdDayAmount": null,
         "amountUnit": null,
         "exceptionType": null,
         "comment": null,
         "paycode": null,
         "paycodeAmountType": null,
         "usedType": null,
         "punchType": null,
         "type": {"name": "pattern"},
         "extendedData": null,
         "dayBased": false
      },
      "policyDefinition":       {
         "id": 404,
         "name": "49899 Consolidated Sick w S&S plc467381724319"
      },
      "ruleDefinition":       {
         "id": 604,
         "name": "WR467381724319"
      },
      "pointTransaction":       {
         "id": 313,
         "name": "Attendance Points 1",
         "employeeId": 385,
         "balanceChange": 5,
         "typeCategory": "POINT",
         "applyDate": "2016-04-28T00:00:00"
      },
      "type": {"name": "pattern"},
      "employeeId": 385,
      "applyDate": "2016-04-28",
      "eventTime": "00:00:00",
      "amount": null,
      "dayAmount": null,
      "updatedByUserId": 12,
      "isSystem": true
   }

1 个答案:

答案 0 :(得分:0)

尝试使用underscore.js lib。 Plunker

   var arr  = [
  { 
  "id": 182,
  "name": "49899 Consol Sick w S&S Pattern"
},
{ 
  "id": 183,
  "name": "49900 Consol Sick w S&S Pattern"
},{ 
  "id": 184,
  "name": "49901 Consol Sick w S&S Pattern"
},{ 
  "id": 185,
  "name": "49902 Consol Sick w S&S Pattern"
},{ 
  "id": 186,
  "name": "49903 Consol Sick w S&S Pattern"
},]


console.log(_.sortBy(arr, 'id'))

或者只是最简单的(例如在plunker中)

var data = [9.0, 8.0, 9.0, 8.0, 8.0, 8.0, 6.0, 5.0]
console.log(data.sort());