【问题标题】:API Call in Processing Error处理错误中的 API 调用
【发布时间】:2018-02-12 19:04:38
【问题描述】:

我正在尝试在处理中执行基本的 JSON GET 操作。我一直在使用两个只需要 API 密钥进行身份验证的开放 API。已收到两次以下错误消息:

无法为http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&APPID=f77c39703fb6be71e2c5a96e58edc077 创建阅读器

我得到的错误信息是:

FATAL EXCEPTION: Animation Thread
Process: processing.test.jsonprocessingtutorial, PID: 26486
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.io.Reader.markSupported()' on a null object reference
    at processing.data.JSONTokener.<init>(Unknown Source)
    at processing.data.JSONObject.<init>(Unknown Source)
    at processing.core.PApplet.loadJSONObject(Unknown Source)
    at processing.test.jsonprocessingtutorial.JSONprocessingtutorial.loadData(JSONprocessingtutorial.java:46)
    at processing.test.jsonprocessingtutorial.JSONprocessingtutorial.setup(JSONprocessingtutorial.java:42)
    at processing.core.PApplet.handleDraw(Unknown Source)
    at processing.core.PSurfaceNone.callDraw(Unknown Source)
    at processing.core.PSurfaceNone$AnimationThread.run(Unknown Source)

API 密钥和 GET 调用已经过双重检查。

The code in Processing is the following: 

String API_Key = "f77c39703fb6be71e2c5a96e58edc077";
String url = "http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139";
//specific url with coordinates for specific city 

void setup() {
  size(480, 360);
  loadData();
  }

void loadData(){
  JSONObject json = loadJSONObject(url+"&APPID="+API_Key);
  JSONObject windData = json.getJSONObject("wind");
  float speed = windData.getFloat("speed");
  println (speed); 
  }

JSON 响应如下: 试图让“速度”出来..

{
"coord": {
"lon": 139,
"lat": 35
},
"weather": [
{
"id": 800,
"main": "Clear",
"description": "clear sky",
"icon": "01n"
}
],
"base": "stations",
"main": {
"temp": 278.455,
"pressure": 1017.64,
"humidity": 100,
"temp_min": 278.455,
"temp_max": 278.455,
"sea_level": 1027.18,
"grnd_level": 1017.64
},
"wind": {
"speed": 11.86,
"deg": 272.003
},
"clouds": {
"all": 0
},
"dt": 1518460865,
"sys": {
"message": 0.0133,
"country": "JP",
"sunrise": 1518384771,
"sunset": 1518423842
},
"id": 1851632,
"name": "Shuzenji",
"cod": 200
}

请指教!谢谢。。

【问题讨论】:

    标签: api processing


    【解决方案1】:

    我找到了我的问题的答案..

    解决方法是使用“Android - Sketch Permissions”选项卡下的“INTERNET Permission”..

    亲切的问候,

    尼尔斯

    【讨论】:

      猜你喜欢
      • 2021-10-24
      • 1970-01-01
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-16
      相关资源
      最近更新 更多