我正在尝试发现已部署,并且我创建了一个简单的数据存储表。该表存储在
http://localhost:2403/table
作为 JSONArray。我可以使用以下代码获取数据:
private static String readAll(Reader rd) throws IOException {
StringBuilder sb = new StringBuilder();
int cp;
while ((cp = rd.read()) != -1) {
sb.append((char) cp);
}
return sb.toString();
}
public static JSONArray readJsonFromUrl(String url) throws IOException, JSONException {
InputStream is = new URL(url).openStream();
try {
BufferedReader rd = new BufferedReader(new InputStreamReader(is, Charset.forName("UTF-8")));
String jsonText = readAll(rd);
JSONArray json = new JSONArray(jsonText);
return json;
} finally {
is.close();
}
}
public static void main(String[] args) throws IOException, JSONException {
JSONArray obj = readJsonFromUrl("http://localhost:2403/table");
}
我的问题是,这些数据存储在本地主机中。假设,我想在我的 android 应用程序中使用这个数据库。那么显然我不能使用
JSONArray obj = readJsonFromUrl("http://localhost:2403/table")
获取 json 数组。那么,我怎样才能得到它?我查看了文档,找不到任何东西。我应该使用什么链接而不是本地主机:2403/表?
谢谢