2017-09-29 66 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; 
}