如何从JSON响应中提取2个字符之间的所有内容? [英] How to extract everything between 2 characters from JSON response?

查看:137
本文介绍了如何从JSON响应中提取2个字符之间的所有内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jmeter 2.8中的正则表达式从JSON响应中提取一些值.

I'm using the regex in Jmeter 2.8 to extract some values from JSON responses.

响应如下:

{
    "key": "prod",
    "id": "p2301d",
    "objects": [{
            "id": "102955",
            "key": "member",
            ...
         }], 
    "features":"product_features"
}

我正在尝试使用正则表达式获取除[{....}]之间的文本以外的所有内容. 我已经尝试过这个"key":([^\[\{.*\}\],].+?),但是我总是得到[{...}]之间的其他值(在此示例中: member )

I'm trying to get everything except the text between [{....}] with one regex. I've tried this one "key":([^\[\{.*\}\],].+?) but I'm always getting the other values between [{...}] (in this example: member)

您有什么线索吗?
谢谢.

Do you have any clue?
Thanks.

推荐答案

针对我的问题,我的解决方案是将JSON转换为对象,以便我可以仅提取所需的值,而不能提取.

My solution for my problem was to turn the JSON into an object so that i can extract just the value that i want, and not the values in the {...}.

在这里您可以看到我的代码:

Here you can see my code:

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 .

这篇关于如何从JSON响应中提取2个字符之间的所有内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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