【发布时间】:2011-02-11 12:30:23
【问题描述】:
我正在尝试使用以下代码访问 json 对象
http://epubreader.XXXXXXX.net/public/json/books.json
try
{
InputStream in = openHttpConnection("http://epubreader.feathersoft.net
/public/json/books.json");
Data=new byte[in.available()];
in.read(Data);
}
catch(IOException e)
{
Log.e("url", e.getLocalizedMessage()+e.getCause()+e.getStackTrace());
}
}
private InputStream openHttpConnection(String url_send) throws IOException
{
InputStream in = null;
int response = -1;
URL url = new URL(url_send);
URLConnection conn = url.openConnection();
if (!(conn instanceof HttpURLConnection))
throw new IOException("Not an HTTP connection");
try {
HttpURLConnection httpConn = (HttpURLConnection) conn;
httpConn.setAllowUserInteraction(false);
httpConn.setInstanceFollowRedirects(true);
httpConn.setRequestMethod("GET");
httpConn.connect();
response = httpConn.getResponseCode();
if (response == HttpURLConnection.HTTP_OK) {
in = httpConn.getInputStream();
}
} catch (Exception ex) {
throw new IOException("Error connecting");
}
return in;
}
}
然后我得到 Nullpointer 异常我无法弄清楚它是什么请帮助我
感谢您的宝贵时间
【问题讨论】:
标签: android web-services json