Gerrit rest api将空JSONArray返回到java环境,但将非空JSONArray返回到浏览器
我面临以下问题: 我想使用此api函数从gerrit存储库获取更改列表 当我在浏览器中发送GET请求时,我得到了响应Gerrit rest api将空JSONArray返回到java环境,但将非空JSONArray返回到浏览器,java,json,api,resteasy,gerrit,Java,Json,Api,Resteasy,Gerrit,我面临以下问题: 我想使用此api函数从gerrit存储库获取更改列表 当我在浏览器中发送GET请求时,我得到了响应 [ { "id": "business~develop~I65d58a2345346cb35a0ecbb63d6ed896c7", "project": "business", "branch": "develop", "hashtags": [], "change_id": "I65d58a2a045645636cb35a0ecbb63d6ed896c7"
[
{
"id": "business~develop~I65d58a2345346cb35a0ecbb63d6ed896c7",
"project": "business",
"branch": "develop",
"hashtags": [],
"change_id": "I65d58a2a045645636cb35a0ecbb63d6ed896c7",
"subject": "Leader property deleted from organizational unit classes. Org unit\u0027s employees cascad type removed. Employee\u0027s roles amount limited by 1 in orgUnit.xsd. Employees identifiers changed in orgUnit.xml. Updated domain model. DataUploadRestService created. Emp",
"status": "NEW",
"created": "2015-05-12 14:31:48.226000000",
"updated": "2015-07-07 07:34:35.195000000",
"mergeable": true,
"insertions": 3100,
"deletions": 1358,
"_number": 589,
"owner": {
"_account_id": 1003473
}
}
]
但当我使用RestEasy发送GET请求时,或者使用Java代码以其他方式发送请求时:
try {
final ResteasyClient client = new ResteasyClientBuilder().build();
final ResteasyWebTarget target = client
.target("https://gml-jbpm.gomel.iba.by/gerrit/changes/");
String response = target.request().get(String.class);
final JSONArray array = new JSONArray(response);
System.out.println("RestEasy response: " + array);
} catch (final Exception e) {
e.printStackTrace();
}
我得到的回答是空的:
[]
如何解决这个问题?为什么我得到空的JSONArray?这可能是因为Gerrit在响应开始时返回了一些魔法字符。您可能想看看这个库,这样您就不必关心JSON了: