Play Framework Java 2.3.8 - JSon

时间:2015-03-16 20:35:05

标签: java json playframework-2.3

  

我试图从模拟中获取一个JSon对象。   当我编译我得到这个错误:

error: package org.json does not exist
In C:\workspace\tutorial\app\controllers\Application.java:18
15import models.Device;   
16import models.Task;
17
18import org(.)json.JSONArray; --> ERROR 
19import org.json.JSONException;
20
21import play.data.Form;
22import play.db.ebean.Model;
23import play.mvc.Controller;

这是我的代码:

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"到plugins.sbt

0 个答案:

没有答案