Wunderground APIから特定の時刻に過去の気温を取得しようとしていますが、次のエラーが表示されます。どんな助けもありがとう!エラーメッセージ:JSONObjectテキストは1で始まる必要があります[文字2行1]
public static void main(String[] args) throws IOException {
try {
String date = "20161211";
String sURL = "http://api.wunderground.com/api/da7962c092ba005b/history_"
+ date + "https://stackoverflow.com/q/autoip.json";
URL url = new URL(sURL);
String temp1 = "";
URLConnection yc = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
JSONObject json = new JSONObject(sURL);
temp1 = json.getJSONObject("observations").getString("tempi");
System.out.println(temp1);
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
そして、私は次のエラーを取得しています:
JSONObject json = new JSONObject(inputLine);
代わりに:あなたはおそらく書きたかった
org.json.JSONException: A JSONObject text must begin with '{' at 1 [character 2 line 1]
at org.json.JSONTokener.syntaxError(JSONTokener.java:432)
at org.json.JSONObject.<init>(JSONObject.java:184)
at org.json.JSONObject.<init>(JSONObject.java:310)
at Weather.main(Weather.java:54)
エラーはかなり明確です。あなたは 'sURL'からjsonオブジェクトを作成していますが、これはjsonではありません。 – tima