2017-07-15 3 views
0

私は、WebアプリケーションのWebパフォーマンステストを行うためにVisual Studio 2013を使用しています.JSONレスポンスから別のリクエストで値を取得したいと考えています。以下は、JSON結果の\ Bjsonレスポンスからjsonレスポンスの値を抽出する#

"ResultMessage": 
    "Success","Result":{"IsAnonymous":false, 
      "DestinationBranchID":"5886c018-0a74-42c0-a334-f221beacdd49", 
      "ID":"83f65759-a442-4dbf-8772-550e5dec7933", 
      "No":943514207446, 
      "DestinationCityID":"43694b12-9c32-49d8-8e02-7663bbf7e07b", 
      "IssueDateTime":"2017-07-15T11:24:38", 
      "Amount":1500.0000, 
      "IsFeeIncluded":false, 
      "NetFee":200.0000, 
      "PayAtCashier":1700.0000, 
      "CustomerIdentityID":"f62c2def-04d8-46e6-a501-5c95423a4292", 
      "ReasonID":"00000000-0000-0000-0000-000000000000", 
      "BenefactorName":null, 
       "BenefactorPhone":null, 
       "BenefactorMobile":null, 
       "BeneficiaryName":"Test", 
       "BeneficiaryPhone":"09918367343", 
       "BeneficiaryMobile":"011686383", 
       "Note":"", 
       "RowVersion":"AAAAAAAAVp4="}} 

私はIDフィールドの値を取得したいですが、私は "IDの\" \この正規表現を試みた: "*?" \を しかし、それは私に全体の "ID"を与えます: "83f65759-a442-4dbf-8772-550e5dec7933"しかし、私はGuidの部分だけが必要です

+0

キャプチャグループで試しましたか? '\" ID \ ":\"(。*?) "'グループ1を試合から得ますか? [ここに例があります](https://www.dotnetperls.com/regex-groups) – LukStorms

答えて

1

私はJSON列の価値を得るためにカスタム抽出ルールを構築し、

public string Name { get; set; } 

    public bool UseArrayResult { get; set; } 

    public string ArrayName { get; set; } 

    public override void Extract(object sender, ExtractionEventArgs e) 
    { 
     if (e.Response.BodyString != null) 
     { 
      var json = e.Response.BodyString; 
      var data = JObject.Parse(json); 
      if (!UseArrayResult) 
      { 
       if (data != null) 
       { 
        e.WebTest.Context.Add(this.ContextParameterName, data.SelectToken(Name)); 
        e.Success = true; 
        return; 
       } 
      } 
      else 
      { 
       var result = data[ArrayName]; 
        if (result != null) 
        { 
         e.WebTest.Context.Add(this.ContextParameterName, result.SelectToken(Name)); 
         e.Success = true; 
         return; 
        } 
      } 
     } 

あなたはここに内部配列とArrayName Paramの内部で必要な値が「結果」と真としてUseArrayResultのParamを送信する必要があります。必要な値が直接存在する場合は、UseArrayResultパラメータをfalseとして送信する必要があります

関連する問題