[英]How to return a JSON Array from java server to ios app
I has an ios app which sends a http request to a REST service I have running on a local server. 我有一个ios应用程序,它向本地服务器上运行的REST服务发送http请求。 The server gets some information from the Twitter api and then sends it back to the ios app. 服务器从Twitter api获取一些信息,然后将其发送回ios应用。 I have put the data I want to send back in a JSONArray. 我已将要发送回的数据放入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. 我想更改,以便它发回“ returnedArray”数组。
@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()
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.