这是我的代码。我在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());
}
}
答案 0 :(得分:0)
您使用的是IDE还是记事本?您的代码会抛出三个例外:MalformedURLException
,IOException
和JSONException
。使用try-catch
进行修复。