JSONPath提取值

时间:2015-02-10 15:05:20

标签: scala jsonpath

我想从以下会员之一中提取所有offerId:

{
   "resultCode": "SUCCESS",
   "errorCode": null,
   "errorMessage": null,
   "membershipCoupons":
   [
       {
           "membershipId": "32021428",
           "coupons":
           [
               {
                   "offerId": "000C291EE8241ED4AAF43058D8564910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8564910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8564910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579699407,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D857A910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D857A910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D857A910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579703400,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D8608910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8608910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8608910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579706707,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D862E910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D862E910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D862E910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579710047,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D87A0910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A0910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A0910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579713540,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D877E910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D877E910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D877E910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579717533,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D87B8910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B8910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B8910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579721123,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D8870910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8870910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8870910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": 1423579724430,
                   "redemption": null
               },
               {
                   "offerId": "000C297765971EE4A8C22C6999219BA4",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201504_003/000C297765971EE4A8C22C6999219BA4Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201504_003/000C297765971EE4A8C22C6999219BA4High.jpg"
                       }
                   ],
                   "endTime": 1425168000000,
                   "activationDate": 1423136616203,
                   "redemption": null
               },
               {
                   "offerId": "000C297765971EE4A8C22C699921FBA4",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201504_003/000C297765971EE4A8C22C699921FBA4Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201504_003/000C297765971EE4A8C22C699921FBA4High.jpg"
                       }
                   ],
                   "endTime": 1425168000000,
                   "activationDate": 1423139501440,
                   "redemption": null
               },
               {
                   "offerId": "000C297765971EE4A8C22C6999233BA4",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201504_003/000C297765971EE4A8C22C6999233BA4Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201504_003/000C297765971EE4A8C22C6999233BA4High.jpg"
                       }
                   ],
                   "endTime": 1425168000000,
                   "activationDate": 1423215586673,
                   "redemption": null
               }
           ]
       },
       {
           "membershipId": "8315319211",
           "coupons":
           [
               {
                   "offerId": "000C291EE8241ED4AAF43058D85CA910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85CA910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85CA910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D85F6910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85F6910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85F6910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D85E2910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85E2910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85E2910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D85FC910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85FC910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D85FC910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D8776910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8776910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D8776910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D87A8910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A8910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87A8910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D87B6910",
                   "description": "nora",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B6910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87B6910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               },
               {
                   "offerId": "000C291EE8241ED4AAF43058D87D0910",
                   "description": "nora.",
                   "graphics":
                   [
                       {
                           "width": 400,
                           "height": 200,
                           "quality": "Low",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87D0910Low.jpg"
                       },
                       {
                           "width": 900,
                           "height": 600,
                           "quality": "High",
                           "url": "https://site/02_201506_011/000C291EE8241ED4AAF43058D87D0910High.jpg"
                       }
                   ],
                   "endTime": 1423353600000,
                   "activationDate": null,
                   "redemption": null
               }
           ]
       }
   ]
}

我有一些适用于memberId的东西,但我想参数化,以便我只选择我在会话中的参数的offerId,我通常会像$ {medlem}一样引用该参数,我使用Scala。

这有效:

.check(jsonPath("$.membershipCoupons[*].coupons[?(@.activationDate==null)].offerId").findAll.optional.saveAs("itemList"))

但是我怎么能用一个指向特定memberId的参数说这个:

     .check(jsonPath("$.membershipCoupons[membershipId[${medlem}]].coupons[?(@.activationDate==null)].offerId").findAll.optional.saveAs("itemList"))

1 个答案:

答案 0 :(得分:0)

我认为你需要分两步操作:

 arrayMembershipId = $.membershipCoupons[*].membershipId
 n = getIndex(membershipIdArray, yourcode)
 arrayOffer = membershipCoupons[n].coupons[?(@.activationDate==null)].offerId