简体   繁体   English

将org.json.JSONArray转换为org.json.simple.JSONArray

[英]Convert org.json.JSONArray to org.json.simple.JSONArray

I have a library return org.json.JSONArray and it needs to be converted to org.json.simple.JSONArray . 我有一个返回org.json.JSONArray的库,它需要转换为org.json.simple.JSONArray

The web server that I use has an interface that returns org.json.simple.JSONArray and therefore I need to convert org.json.JSON array to it. 我使用的Web服务器具有返回org.json.simple.JSONArray的接口,因此我需要将org.json.JSON array转换org.json.JSON array接口。

I also tried converting the response to org.json.JSONArray but the web server based on Jersey is not able to convert it into a HTTP response. 我还尝试将响应转换为org.json.JSONArray但是基于Jersey的Web服务器无法将其转换为HTTP响应。

Was able to make the library (A Unirest wrapper) that returns org.json.JSONArray return in the org.json.simple.JSONArray form. 能够使返回org.json.JSONArray的库(一个Unirest包装器)以org.json.simple.JSONArray形式返回。 Which solved the issue. 解决了问题。

    Unirest.setTimeouts(1000000,1000000);
    HttpResponse<String> jsonResponse = Unirest.post(host)
            .header("Content-Type", "application/json")
            .body(String.format("{\"queryType\":\"%s\", \"query\":\"%s\"}", "SQL",
                    query))
            .asString();
    JSONParser parser = new JSONParser();
    String json = jsonResponse.getBody();
    return (JSONObject) parser.parse(json);

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

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