无法初始化类型jsonobject

时间:2014-02-11 11:45:41

标签: json

这是我的代码。我在JSONObject json = new JSONObject(builder.toString());这行我无法解决的错误,如果我犯了任何错误,可能有人告诉我。这是我在这一行得到的错误'无法初始化类型jsonobject'。

public class Findrss {

    public static <JSONObject> void main(String[] args) {
        URL url = new URL("https://ajax.googleapis.com/ajax/services/feed/find?"
        + "v=1.0&q=Official%20Google%20Blog&userip=INSERT-USER-IP");
        java.net.URLConnection connection = url.openConnection();
        String ref = "google.com";

        connection.addRequestProperty("Referer", ref);

        String line;
        StringBuilder builder = new StringBuilder();
        BufferedReader reader = new BufferedReader(
            new InputStreamReader(connection.getInputStream()));

        while((line = reader.readLine()) != null) {
            builder.append(line);
        }

        JSONObject json = new JSONObject(builder.toString());
    }

}

1 个答案:

答案 0 :(得分:0)

您使用的是IDE还是记事本?您的代码会抛出三个例外:MalformedURLExceptionIOExceptionJSONException。使用try-catch进行修复。

相关问题