播放框架Java 2.3.8-JSon
我试图从模拟中获取JSon对象。 编译时,我遇到了以下错误: 这是我的代码:播放框架Java 2.3.8-JSon,java,json,playframework-2.3,Java,Json,Playframework 2.3,我试图从模拟中获取JSon对象。 编译时,我遇到了以下错误: 这是我的代码: public static Result index() throws JSONException, IOException { JSONArray json = readJsonFromUrl("http://htejera.ukelelestudio.com/mock/dmamock/devices/android"); return ok(index.render(json.toString())
public static Result index() throws JSONException, IOException {
JSONArray json = readJsonFromUrl("http://htejera.ukelelestudio.com/mock/dmamock/devices/android");
return ok(index.render(json.toString()));
}
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();
}
}
我已将libraryDependencies+=“org.json”%%“json”%%“20140107”添加到插件中。sbt您不使用Play的json库有什么原因吗?它不会使用Play的json库进行编译。-->20080701同意@soong,Play默认包含Codehaus的JSON Jackson库,它满足了所有的需求。我遇到了同样的错误,这就是为什么我试图在构建中升级到一个新版本。
public static Result index() throws JSONException, IOException {
JSONArray json = readJsonFromUrl("http://htejera.ukelelestudio.com/mock/dmamock/devices/android");
return ok(index.render(json.toString()));
}
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();
}
}