I has an ios app which sends a http request to a REST service I have running on a local server. The server gets some information from the Twitter api and then sends it back to the ios app. I have put the data I want to send back in a JSONArray. How do I go about sending this array back as a response to the request.
I have included the method that receives the request and which initially sent back a string. I would like to change so it sends back the "returnedArray" array instead.
@Path("/hello")
public class HelloResource {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayHello() throws JSONException {
String convert = null;
JSONArray returnedArray = new JSONArray();
try {
returnedArray = TweetUsingTwitter4jExample.getTweets();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return convert;
}
}
在JSONArray上调用toString()
。
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.