jmeter groovy:如何从json中获得属性,属性以一个数字开头
我确实有以下我的jsonslurper()到JSON的字符串。
{"id":"1111","fields":{"2_attribute":"111111","3_attribute":"11122222","4_attribute":"1111222211"}
我在JSR223中使用的预处理器groovy脚本在以下代码log.info(“ attribute2:” + json2.fields.2_attribute);
中获取属性“ 2_attribute”值,并获得以下例外:
2022-06-01 13:18:25,491 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor2
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script197.groovy: 24: Number ending with underscores is invalid @ line 24, column 50 @ line 24, column 50.
age_type_id:" + json2.fields.2_attribute
我如何设法获得价值? 属性命名不会改变。
谢谢。
I do have the following string which I parse with the JsonSlurper() to json.
{"id":"1111","fields":{"2_attribute":"111111","3_attribute":"11122222","4_attribute":"1111222211"}
I'm using in a JSR223 PreProcessor groovy script to get attribute "2_attribute" value with the following code log.info("attribute2 :" + json2.fields.2_attribute);
and getting the following exception:
2022-06-01 13:18:25,491 ERROR o.a.j.m.JSR223PreProcessor: Problem in JSR223 script, JSR223 PreProcessor2
javax.script.ScriptException: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
Script197.groovy: 24: Number ending with underscores is invalid @ line 24, column 50 @ line 24, column 50.
age_type_id:" + json2.fields.2_attribute
How could I manage to get the value?
attribute naming cannot change.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您需要将此
2_Attribute
带有引号,就像Groovy对象名称中的名称不能以数字开头。演示:
更多信息:
I think you need to surround this
2_attribute
with quotation marks as in Groovy object names cannot start with a number.Demo:
More information: