如何从JSON响应中提取2个字符之间的所有内容?
问题内容:
我在Jmeter 2.8中使用正则表达式从JSON响应中提取一些值。
响应是这样的:
{
"key": "prod",
"id": "p2301d",
"objects": [{
"id": "102955",
"key": "member",
...
}],
"features":"product_features"
}
我正在尝试[{....}]
使用一个正则表达式之间除文本之外的所有内容。我已经尝试过一个,"key":([^\[\{.*\}\],].+?)
但是我总是得到其他值[{...}]
(在此示例中:
member )
你有什么线索吗?
谢谢。
问题答案:
对于我的问题,我的解决方案是将JSON转换为对象,以便我可以仅提取所需的值,而不能提取中的值{...}
。
在这里您可以看到我的代码:
var JSON={"itemType":"prod","id":"p2301d","version":"10","tags":[{"itemType":"member","id":"p2301e"},{"itemType":"other","id":"prod10450"}],"multiPrice":null,"prices":null};
//Transformation into an object:
obj = eval(JSON );
//write in the Jmeter variable "itemtype", the content of obj.itemType:prod
vars.put("itemtype", obj.itemType);
有关更多信息:http :
//www.havecomputerwillcode.com/blog/?p=500。