JMeter return JSON data extraction method

Source: Internet
Author: User
Tags response code

In JMeter, the response returns JSON-formatted data in the following format:

{    "code": +,    "message": "Success",    "Body":    [        {"code": "0001", "desc": "Value 1", "Sortno": 1},        {"code": "0002", "desc": "Value 2", "Sortno": 2},        {"code": "0003", "Desc": "Value 3", "Sortno": 3}    ]}

Data extraction methods:

Regular Expression Extraction

Description of the regular expression extractor:

Apply to:The scope of application (typically select the default main sample only), even if there is a redirect, it is generally the interface to extract the final request. response fields to check for:The sample data source. Main body: Interface response body content, generally to extract the normal HTTP response results of data, all tick this. Information header: All the contents of the response header.Request Headers:All the contents of the request header. URL: is to match the URL of sample, that is, to see the first line URL of the request content in the result tree, does not contain the request parameters in data (that is, only match protocol (protocol) +host+path+querystring, such as: https://  WWW.BAIDU.COM/INDEX.PHP?TN=MONLINE_3_DG).  Response Code: HTTP response code, such as 101,200,302,404,501. Response Information: The response information for the HTTP response code, for example: OK, Found (http/1.1 ok;http/1.1 302 Found). Reference Name:The name of the variable when referenced elsewhere, the name can only be one, reference method: ${test}

Regular Expressions: data Extractor, the general simple general syntax is: the left edge (. *?) The right boundary, the left and the the boundary is to be able to accurately locate the content that wants to match, inside of '? ' For a non-greedy match, (non-greedy mode means that the match is stopped after encountering the first right boundary, so that you can get exactly what you want). It is recommended that you use a non-greedy match unless you have special circumstances.

Template:corresponding to the regular expression extractor type, the style is:$n $。 If the template is: $0$, the content that matches the entire expression is the content enclosed in parentheses, i.e. ("Code": "0001", "Desc": "Value 1", "Sortno": 1)。 If the template is: $1$, it corresponds to the first (. *) in the regular expression. The matching content, i.e. (0001), if the template is:$2$, the second (. *?) in the corresponding regular expression. The matching content, i.e. (value 1), if the template is $1$$2$, then put 2 (. *?) The matching content is stitched together, i.e. (0001 value 1). Templates are freely combinable and are described in subsequent cases. Match numbers:The final result of the regular expression matching data can be considered as an array, and the matching number is considered to be the first element of the array. When 0 o'clock, the matching data is returned randomly. When 1 o'clock, indicates that the first element of the array of matching results is returned. When a negative number ( -1,-2,-100 is available), a variable that returns all elements and returns a total of one element at a time${test_matchnr}At the time of reference: by${test_1}The way to fetch the 1th matching content,${test_2}To fetch the 2nd matching content. Default value:The default value when the match fails. Usually used for subsequent logical judgments, it is recommended to use some special meanings, such as 0,null,error.

JSON Extractor

Http://www.cnblogs.com/rechin/p/8662744.html

JMeter return JSON data extraction method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.