Jmeter:使用特殊/空格字符提取 JSON 响应 [英] Jmeter: Extracting JSON response with special/spaces characters

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

问题描述

你好,谁能帮我提取用户参数testuser1"的值

我尝试使用这个 JSON 路径表达式 $..data 我能够提取整个响应但无法提取用户参数.提前致谢

{数据":{": 13, timed_out";:假,_shards";:{总": 5、《成功》: 5、跳过":0,失败";: 0 }, "命中";:{总":1,max_score";:1.0,命中": [ { "_index";:bushidodb_history_network_eval_ea9656ef-0a9b-474b-8026-2f83e2eb9df1_2021-april-10",_type":网络",_id";:6e2e58be-0ccf-3fb4-8239-1d4f2af322e21618059082000",_score":1.0,_source";:{不匹配";:[协议"、状态"、命令";],实例":e3032804-4b6d-3735-ac22-c827950395b4|0.0.0.0|10.179.155.155|53|UDP"、协议":UDP",本地地址";:0.0.0.0",本地端口";: "12345", "foreignAddress";:10.179.155.155"、foreignPort":53",命令";:ping yahoo.com",用户":testuser1",pid";:10060",状态";: OUTGOINGFQ", 率";:216.0,原始本地地址";:192.168.100.229",exe":/bin/ping",md5";:f9ad63ce8592af407a7be43b7d5de075"、dir": "", "agentId";:abcd-dcd123",年份";:2021"、月":四月",天":10"、小时":12",时间";:1618059082000",isMerged":假,时间戳";:2021 年 4 月 10 日下午 12:51:22",metricKey":6e2e58be-0ccf-3fb4-8239-1d4f2af322e2"、isCompliant": false }, "排序";: [ 1618059082000 ] } ] }, 聚合";:{count_over_time";:{桶": [ { "key_as_string";:2021-04-10T08:00:00.000-0400",钥匙":1618056000000,doc_count";: 1 } ] } }}",成功":真实,消息":{代码":S",message":Get Eval results Count Success"}}

实际响应:

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

  • 演示:

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

    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 响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆