I would like to send a get
request to a remote server using Restlet
and receive the response (as Json
).
Here is my starting point, please feel free to complete:
ClientResource cr = new ClientResource("https://"+url);
JsonRepresentation r = (JsonRepresentation) cr.get();
r.getJsonObject().get("MY_VALUE");
Restlet version 2.1.7
Json : {"title":"General Terms & Conditions","version":"20022014_001"}
In fact, you don't use the JsonRepresentation
the right way. The method get
of the class ClientResource
doesn't return an element of such type. You must use it as described below:
ClientResource cr = new ClientResource("https://"+url);
Representation repr = cr.get();
JsonRepresentation jsonRepr = new JsonRepresentation(repr);
String value = jsonRepr.getJsonObject().get("MY_VALUE");
Hope it helps you, Thierry
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.