简体   繁体   English

在SoapUI groovy上使用json.org

[英]Use json.org on SoapUI groovy

I'm trying to use org.json on groovy SoapUI to convert a JSON string into XML. 我正在尝试在groovy SoapUI上使用org.json将JSON字符串转换为XML。

But When I'm trying to perform my groovy script (this one) 但是当我尝试执行常规脚本时(这个)

import org.json.JSONObject
import org.json.XML

    def str = "{'name':'JSON','integer':1,'double':2.0,'boolean':true,'nested':{'id':42},'array':[1,2,3]}";  
    JSONObject json = new JSONObject(str);
    String xml = XML.toString(json);
    log.info(xml)

I'm getting an error "unable to resolve class org.json.JSONObject , line 1, column 1. 我收到一个错误“无法解析org.json.JSONObject类,第1行,第1列。

I downloaded the jar on http://mvnrepository.com/artifact/org.json/json/20141113 , I put it on SoapUI/bin/ext but It's not working. 我在http://mvnrepository.com/artifact/org.json/json/20141113上下载了jar,我将其放在SoapUI / bin / ext上,但无法正常工作。

Can someone please help me with this? 有人可以帮我吗?

Coping the json-20141113.jar in SOAPUI_HOME\\bin\\ext works for me, and your code executes correctly, logging this: 应对SOAPUI_HOME\\bin\\extjson-20141113.jar对我SOAPUI_HOME\\bin\\ext ,并且您的代码正确执行,记录如下:

Thu Feb 12 21:58:53 CET 2015:INFO:<boolean>true</boolean><array>1</array><array>2</array><array>3</array><double>2.0</double><name>JSON</name><integer>1</integer><nested><id>42</id></nested>

Note that in order to load the libraries you must restart SOAPUI , maybe this is causing your error. 请注意,为了加载库,必须重新启动SOAPUI ,这可能是导致您出错的原因。

Note also that the jar you linked is compiled with java 1.8 so check if you run SOAPUI using this version of java if not then you will receive Unsupported major.minor version 52.0 error. 还要注意,链接的jar是用java 1.8编译的,因此请检查是否使用此版本的Java运行SOAPUI ,否则会收到Unsupported major.minor version 52.0错误。 I say this because SOAPUI is available to download with or without java; 我之所以SOAPUI说,是因为SOAPUI有没有Java,都可以下载SOAPUI if you download it with java the version is java 1.7 . 如果使用Java下载,则版本为java 1.7 If this is the case you must download java 1.8 and modify SOAPUI_HOME\\bin\\soapui.bat to use the correct version. 如果是这种情况,则必须下载java 1.8并修改SOAPUI_HOME\\bin\\soapui.bat以使用正确的版本。

Hope this helps, 希望这可以帮助,

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM