2017-09-29 59 views
2

我有一个简单的JSON,我想获得两个属性:如何从json中使用jsonpath获取多个元素?

corematching并验证是否core : truematching : true

{ 

    "lockVersion" 
    : 1, 

    "updatedBy" : "jan", 

    "updatedOn" : "2016-09-25T11:21:45Z", 

    "id" : 964, 

    "title" : "Corporate Numeric", 

    "description" : null, 

    "descType" : 31084140, 

    "descValueType" : 31084136, 

    "defaultSourceOfVerification" : "Source", 

    "core" : true, 

    "matching" : true, 

    "anything" : 
    [ 

    ], 

    "authorized" 
    : 
    [ 
     1 
    ] 


} 

是否有可能使用AND运算符执行此操作,还是必须执行两步操作来提取一个集合,然后再次筛选以获得最终结果? 我打算使用jp @ gc - JSON Path Assertion。

回答

1

请参阅Dmitri T answer JSON路径断言插件。

所以使用核心JMeter的,你可以使用JSON ExtractorResponse Assertion与范围做这样的 “JMeter的变量”:

enter image description here

enter image description here

enter image description here

enter image description here

+0

@The不错downvoters,可你把你为什么downvoted评论?我仍然爱你:-) –

-1

您应该能够使用BeanShell断言和内置的JSON解析器来实现此目的。

import net.minidev.json.parser.JSONParser; 
import net.minidev.json.JSONObject; 
import net.minidev.json.JSONArray; 


try { 

    // Use JSONParser to parse the JSON 
    JSONParser parser = new JSONParser(JSONParser.ACCEPT_NON_QUOTE|JSONParser.ACCEPT_SIMPLE_QUOTE); 
    JSONObject rootObject = (JSONObject) parser.parse(prev.getResponseDataAsString()); 

    if (rootObject.get("matching") && rootObject.get("core")) { 
     Failure=false; 
    } 
    else { 
     Failure=true; 
    } 


} 
catch (Exception ex) { 
    log.info("Exception.." + ex); 
    Failure=true; 
}