我使用 Java 调用服务器以接收 json 信息,并且我想通过 Rest Web 服务检索该信息。现在我有这个代码:
public class consult {
public static void consult1() the url that retrieves json);
InputStream response = url.openStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(response));
for (String line; (line = reader.readLine()) != null;) {
System.out.println(line);
}
reader.close();
}
这在控制台上完美地显示了 Json,但是如何将信息设置为某个变量,以便当我在浏览器(/resources/consult/)中调用此 WS 时根据此 WS 显示信息?
@Path("/consult")
public class ConsultJSON {
@GET
@Produces ("application/json")
public String getInfo() throws MalformedURLException, IOException {
return consult.consult1();
}