在Android的webservice Rest中读取Json。FileNotFoundException
有人知道为什么不在android中使用json吗 结果是FileNotFoundException,但在导航器上工作 编辑:在Android的webservice Rest中读取Json。FileNotFoundException,android,json,web-services,rest,filenotfoundexception,Android,Json,Web Services,Rest,Filenotfoundexception,有人知道为什么不在android中使用json吗 结果是FileNotFoundException,但在导航器上工作 编辑: public static String readUrl(String urlString) throws Exception { BufferedReader reader = null; try{ URL url = new URL(urlString); reader = new Bu
public static String readUrl(String urlString) throws Exception {
BufferedReader reader = null;
try{
URL url = new URL(urlString);
reader = new BufferedReader(new InputStreamReader (url.openStream()));
StringBuffer buffer = new StringBuffer();
int read;
char[]chars = new char[1024];
while ((read = reader.read(chars)) != -1)
buffer.append(chars, 0, read);
return buffer.toString();
} finally {
if (reader != null)
reader.close();
}
格式错误。
使用{“name”:“string”,“…:”}格式错误。
使用{“name”:“string”,“…:”}使用BufferedReader不是执行此任务的最佳方法。 使用库org.json.*将HttpClient与下面的示例一起使用会更好
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.*****.com/json");
// Execute HTTP Post Request
HttpResponse response = httpClient.execute(post);
String respStr = EntityUtils.toString(response.getEntity());
JSONArray respJSON = new JSONArray(respStr);
使用BufferedReader不是执行此任务的最佳方法。 使用库org.json.*将HttpClient与下面的示例一起使用会更好
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost("http://www.*****.com/json");
// Execute HTTP Post Request
HttpResponse response = httpClient.execute(post);
String respStr = EntityUtils.toString(response.getEntity());
JSONArray respJSON = new JSONArray(respStr);
问题解决了,我正在使用spring,我在服务中删除了它
@RequestMapping(value="/categorias", method = RequestMethod.GET,headers="Accept=application/json")
public @ResponseBody Portada getCategorias() {
到
现在开始工作了 问题解决了,我正在使用spring,并在服务中删除了它
@RequestMapping(value="/categorias", method = RequestMethod.GET,headers="Accept=application/json")
public @ResponseBody Portada getCategorias() {
到
现在开始工作了