我想使用 ReSTLet
向远程服务器发送 get
请求并接收响应(作为 Json
)。
这是我的出发点,请随意完成:
ClientResource cr = new ClientResource("https://"+url);
JsonRepresentation r = (JsonRepresentation) cr.get();
r.getJsonObject().get("MY_VALUE");
ReSTLet版本2.1.7
Json:{"title":"一般条款和条件","version":"20022014_001"}
最佳答案
事实上,您没有以正确的方式使用JsonRepresentation
。 ClientResource
类的方法 get
不会返回此类类型的元素。您必须按照如下所述使用它:
ClientResource cr = new ClientResource("https://"+url);
Representation repr = cr.get();
JsonRepresentation jsonRepr = new JsonRepresentation(repr);
String value = jsonRepr.getJsonObject().get("MY_VALUE");
希望对你有帮助 蒂埃里
关于java - ReSTLet 向服务器发送 "get"请求并处理响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28677881/