本文介绍了Jmeter:使用特殊/空格字符提取JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,有人可以帮我提取"testuser1"用户参数的值吗?

我尝试使用此JSON路径表达式$ .. data我能够提取整个响应,但无法提取用户参数.预先感谢

{数据":"{:13,"timed_out";:否,"_ shards";:{"total"5:成功";5:跳过";:0,失败";:0},"hits";:{"total":1,"max_score":1.0,"hits":[{:"bushidodb_history_network_eval_ea9656ef-0a9b-474b-8026-2f83e2eb9df1_2021-april-10","_ type":"network","_ id";:"6e2e58be-0ccf-3fb4-8239-1d4f2af322e21618059082000","_ score"和":1.0,"_ source":{"misMatches":[协议",状态",命令";],实例":"e3032804-4b6d-3735-ac22-c827950395b4 | 0.0.0.0 | 10.179.155.155 | 53 | UDP",协议":"UDP","localAddress";:"0.0.0.0","localPort";:"12345","foreignAddress";:"10.179.155.155","foreignPort";:"53",命令";:"ping yahoo.com",用户":"testuser1","pid";:"10060",状态";:"OUTGOINGFQ","rate":216.0,"originalLocalAddress";:"192.168.100.229","exe";:"/bin/ping","md5";:"f9ad63ce8592af407a7be43b7d5de075","dir":","agentId";:"abcd-dcd123",年份";:"2021",月";:"APRIL",天";:"10",小时":"12",时间";:"1618059082000","isMerged";:假,时间戳";:"2021年4月10日12:51:22 PM","metricKey":"6e2e58be-0ccf-3fb4-8239-1d4f2af322e2",符合":false},"sort";:[1618059082000]}]},聚合":{" count_over_time":{"buckets":[{" key_as_string":"2021-04-10T08:00:00.000-0400&",键":1618056000000,"doc_count";:1}]}}}",成功":是的,邮件":{"code":"S",消息":获得评估结果计数成功".}}

实际反应:

  • $ {data} JMeter变量中将 user 属性值提取到JMeter变量中:

  • 演示:

    如果响应看起来完全像您发布的那样,则将无法使用JSON提取器,并且必须将其视为普通文本,因此您的选择仅限于

    Hello can someone help me extract the value of user parameter which is "testuser1"

    I tried to use this JSON Path expression $..data I was able to extract the entire response but unable to extract user parameter. Thanks in advance

    {"data": "{ "took" : 13, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "bushidodb_history_network_eval_ea9656ef-0a9b-474b-8026-2f83e2eb9df1_2021-april-10", "_type" : "network", "_id" : "6e2e58be-0ccf-3fb4-8239-1d4f2af322e21618059082000", "_score" : 1.0, "_source" : { "misMatches" : [ "protocol", "state", "command" ], "instance" : "e3032804-4b6d-3735-ac22-c827950395b4|0.0.0.0|10.179.155.155|53|UDP", "protocol" : "UDP", "localAddress" : "0.0.0.0", "localPort" : "12345", "foreignAddress" : "10.179.155.155", "foreignPort" : "53", "command" : "ping yahoo.com ", "user" : "testuser1", "pid" : "10060", "state" : "OUTGOINGFQ", "rate" : 216.0, "originalLocalAddress" : "192.168.100.229", "exe" : "/bin/ping", "md5" : "f9ad63ce8592af407a7be43b7d5de075", "dir" : "", "agentId" : "abcd-dcd123", "year" : "2021", "month" : "APRIL", "day" : "10", "hour" : "12", "time" : "1618059082000", "isMerged" : false, "timestamp" : "Apr 10, 2021 12:51:22 PM", "metricKey" : "6e2e58be-0ccf-3fb4-8239-1d4f2af322e2", "isCompliant" : false }, "sort" : [ 1618059082000 ] } ] }, "aggregations" : { "count_over_time" : { "buckets" : [ { "key_as_string" : "2021-04-10T08:00:00.000-0400", "key" : 1618056000000, "doc_count" : 1 } ] } }}","success": true,"message": {"code": "S","message": "Get Eval results Count Success"}}

    Actual Response:

    Images

    解决方案

    What you posted doesn't look like a valid JSON to me.

    If in reality you're getting what's in your image, to wit:

    {
      "data": "{ \"took\" : 13, \"timed_out\" : false, \"_shards\" : { \"total\" : 5, \"successful\" : 5, \"skipped\" : 0, \"failed\" : 0 }, \"hits\" : { \"total\" : 1, \"max_score\" : 1.0, \"hits\" : [ { \"_index\" : \"bushidodb_history_network_eval_ea9656ef-0a9b-474b-8026-2f83e2eb9df1_2021-april-10\", \"_type\" : \"network\", \"_id\" : \"6e2e58be-0ccf-3fb4-8239-1d4f2af322e21618059082000\", \"_score\" : 1.0, \"_source\" : { \"misMatches\" : [ \"protocol\", \"state\", \"command\" ], \"instance\" : \"e3032804-4b6d-3735-ac22-c827950395b4|0.0.0.0|10.179.155.155|53|UDP\", \"protocol\" : \"UDP\", \"localAddress\" : \"0.0.0.0\", \"localPort\" : \"12345\", \"foreignAddress\" : \"10.179.155.155\", \"foreignPort\" : \"53\", \"command\" : \"pingyahoo.com\", \"user\" : \"testuser1\", \"pid\" : \"10060\", \"state\" : \"OUTGOINGFQ\", \"rate\" : 216.0, \"originalLocalAddress\" : \"192.168.100.229\", \"exe\" : \"/bin/ping\", \"md5\" : \"f9ad63ce8592af407a7be43b7d5de075\", \"dir\" : \"\", \"agentId\" : \"abcd-dcd123\", \"year\" : \"2021\", \"month\" : \"APRIL\", \"day\" : \"10\", \"hour\" : \"12\", \"time\" : \"1618059082000\", \"isMerged\" : false, \"timestamp\" : \"Apr10, 202112: 51: 22PM\", \"metricKey\" : \"6e2e58be-0ccf-3fb4-8239-1d4f2af322e2\", \"isCompliant\" : false }, \"sort\" : [ 1618059082000 ] } ] }, \"aggregations\" : { \"count_over_time\" : { \"buckets\" : [ { \"key_as_string\" : \"2021-04-10T08: 00: 00.000-0400\", \"key\" : 1618056000000, \"doc_count\" : 1 } ] } }}",
      "success": true,
      "message": {
        "code": "S",
        "message": "Get Eval results Count Success"
      }
    }
    

    the easiest way is just using 2 JSON Extractors:

    1. Extract data attribute value into a JMeter Variable from the response

    2. Extract user attribute value into a JMeter variable from ${data} JMeter Variable:

    Demo:

    If the response looks like exactly you posted you won't be able to use JSON Extractors and will have to treat it as normal text so your choice is limited to Regular Expression Extractor, example regular expression:

    "user"\s*:\s*"(\w+)"
    

    这篇关于Jmeter:使用特殊/空格字符提取JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    07-26 04:41