所以我在我的小JSON解析应用程序中获得No Value For可见性错误。
如果我运行Log.i(TAG,可见性);我得到了结果。当我进行LogCat输出时,我得到了所有数据的结果,但是,它们没有被推入我的列表....
不确定我在这里缺少什么。如果我在LogCat中得到它,为什么我没有把它放到我的列表中?
这是我的班级:
public class DarkSkyForecast extends NavigationActivity {
private static final String TAG = "DarkSkyForecast";
private AQuery aq;
private ProgressDialog dialog;
private ListView lv;
protected Object WXAdapter;
String time = null;
String summary = null;
String icon = null;
String precipIntensity = null;
String temperature = null;
String windSpeed = null;
String windBearing = null;
String cloudCover = null;
String humidity = null;
String pressure = null;
String visibility = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setSubtitle("Hourly Weather Forecast");
setContentView(R.layout.darksky_item);
aq = new AQuery(this);
dialog = new ProgressDialog(this);
dialog.setCancelable(true);
dialog.setInverseBackgroundForced(false);
dialog.setCanceledOnTouchOutside(true);
dialog.setMessage("Fetching nearby weather conditions...");
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
work();
}
public void work() {
//truckee
String url = "https://api.forecast.io/forecast/071b586662cdc405e80ee0e3021ea590/39.31667,-120.13333";
aq.progress(dialog).ajax(url, JSONObject.class, this, "dsWX");
}
public void dsWX(String url, JSONObject json, AjaxStatus status) {
if (json != null) {
try {
JSONObject JSONhourly = json.getJSONObject("hourly");
//Log.v(TAG, JSONhourly.toString());
JSONArray hourlyArray = JSONhourly.getJSONArray("data");
List<DarkSkyWx> wx = new ArrayList<DarkSkyWx>();
for (int i = 0; i < hourlyArray.length(); i++) {
JSONObject hourlyData = hourlyArray.getJSONObject(i);
time = hourlyData.getString("time");
summary = hourlyData.getString("summary");
icon = hourlyData.getString("icon");
precipIntensity = hourlyData.getString("precipIntensity");
temperature = hourlyData.getString("temperature");
windSpeed = hourlyData.getString("windSpeed");
windBearing = hourlyData.getString("windBearing");
cloudCover = hourlyData.getString("cloudCover");
humidity = hourlyData.getString("humidity");
pressure = hourlyData.getString("pressure");
visibility = hourlyData.getString("visibility");
Log.i(TAG,time+" : "+ summary+" : "+ icon+" : "+ precipIntensity+" : "+
temperature+" : "+ windSpeed+" : "+ windBearing+" : "+ cloudCover+" : "+
humidity+" : "+ pressure+" : "+ visibility);
wx.add(new DarkSkyWx(time, summary, icon, precipIntensity,
temperature, windSpeed, windBearing, cloudCover,
humidity, pressure, visibility));
}
lv = (ListView) findViewById(R.id.list);
lv.setAdapter(new WXAdapter(this,
android.R.layout.simple_list_item_1, wx));
} catch (JSONException e) {
Log.e(TAG, e.getMessage());
}
} else {
// ajax error, show error code
Toast.makeText(aq.getContext(), "Error:" + status.getCode(),
Toast.LENGTH_LONG).show();
}
}
private class WXAdapter extends ArrayAdapter<DarkSkyWx> {
private List<DarkSkyWx> items;
public WXAdapter(Context context, int textViewResourceId,
List<DarkSkyWx> items) {
super(context, textViewResourceId, items);
this.items = items;
}
// Create a title and detail, icon is created in the xml file
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
if (v == null) {
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.darksky_item, null);
}
DarkSkyWx o = items.get(position);
if (o != null) {
TextView time = (TextView) v.findViewById(R.id.time);
TextView summary = (TextView) v.findViewById(R.id.summary);
TextView icon = (TextView) v.findViewById(R.id.icon);
TextView precipIntensity = (TextView) v
.findViewById(R.id.precipIntensity);
TextView temperature = (TextView) v
.findViewById(R.id.temperature);
TextView windSpeed = (TextView) v.findViewById(R.id.windSpeed);
TextView windBearing = (TextView) v
.findViewById(R.id.windBearing);
TextView cloudCover = (TextView) v
.findViewById(R.id.cloudCover);
TextView humidity = (TextView) v.findViewById(R.id.humidity);
TextView pressure = (TextView) v.findViewById(R.id.pressure);
TextView visibility = (TextView) v
.findViewById(R.id.visibility);
if (time != null) {
time.setText(o.getTime());
}
if (summary != null) {
summary.setText(o.getSummary());
}
if (icon != null) {
icon.setText(o.getIcon());
}
if (precipIntensity != null) {
precipIntensity.setText(o.getPrecipIntensity());
}
if (temperature != null) {
temperature.setText(o.getTemperature());
}
if (windSpeed != null) {
windSpeed.setText(o.getWindSpeed());
}
if (windBearing != null) {
windBearing.setText(o.getWindBearing());
}
if (cloudCover != null) {
cloudCover.setText(o.getCloudCover());
}
if (humidity != null) {
humidity.setText(o.getHumidity());
}
if (pressure != null) {
pressure.setText(o.getPressure());
}
if (visibility != null) {
visibility.setText(o.getVisibility());
}
}
return v;
}
}
}
我的吸气者/二传手:
public class DarkSkyWx {
private String time;
private String summary;
private String icon;
private String precipIntensity;
private String temperature;
private String windSpeed;
private String windBearing;
private String cloudCover;
private String humidity;
private String pressure;
private String visibility;
public DarkSkyWx(String time, String summary, String icon,
String precipIntensity, String temperature, String windSpeed,
String windBearing, String cloudCover, String humidity,
String pressure, String visibility) {
this.time = time;
this.summary = summary;
this.icon = icon;
this.precipIntensity = precipIntensity;
this.temperature = temperature;
this.windSpeed = windSpeed;
this.windBearing = windBearing;
this.cloudCover = cloudCover;
this.humidity = humidity;
this.pressure = pressure;
this.visibility = visibility;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getSummary() {
return summary;
}
public void setSummary(String summary) {
this.summary = summary;
}
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
public String getPrecipIntensity() {
return precipIntensity;
}
public void setPrecipIntensity(String precipIntensity) {
this.precipIntensity = precipIntensity;
}
public String getTemperature() {
return temperature;
}
public void setTemperature(String temperature) {
this.temperature = temperature;
}
public String getWindSpeed() {
return windSpeed;
}
public void setWindSpeed(String windSpeed) {
this.windSpeed = windSpeed;
}
public String getWindBearing() {
return windBearing;
}
public void setWindBearing(String windBearing) {
this.windBearing = windBearing;
}
public String getCloudCover() {
return cloudCover;
}
public void setCloudCover(String cloudCover) {
this.cloudCover = cloudCover;
}
public String getHumidity() {
return humidity;
}
public void setHumidity(String humidity) {
this.humidity = humidity;
}
public String getPressure() {
return pressure;
}
public void setPressure(String pressure) {
this.pressure = pressure;
}
public String getVisibility() {
return visibility;
}
public void setVisibility(String visibility) {
this.visibility = visibility;
}
}
e.printStackTrace();输出:
03-28 07:35:10.638: W/System.err(24234): org.json.JSONException: No value for visibility
03-28 07:35:10.638: W/System.err(24234): at org.json.JSONObject.get(JSONObject.java:354)
03-28 07:35:10.638: W/System.err(24234): at org.json.JSONObject.getString(JSONObject.java:510)
03-28 07:35:10.638: W/System.err(24234): at com.backcountryskiers.avalanche.conditions.DarkSkyForecast.dsWX(DarkSkyForecast.java:96)
03-28 07:35:10.638: W/System.err(24234): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 07:35:10.646: W/System.err(24234): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 07:35:10.646: W/System.err(24234): at com.androidquery.util.AQUtility.invokeMethod(AQUtility.java:200)
03-28 07:35:10.646: W/System.err(24234): at com.androidquery.util.AQUtility.invokeHandler(AQUtility.java:177)
03-28 07:35:10.646: W/System.err(24234): at com.androidquery.callback.AbstractAjaxCallback.callback(AbstractAjaxCallback.java:497)
03-28 07:35:10.646: W/System.err(24234): at com.androidquery.callback.AbstractAjaxCallback.afterWork(AbstractAjaxCallback.java:1262)
03-28 07:35:10.646: W/System.err(24234): at com.androidquery.callback.AbstractAjaxCallback.run(AbstractAjaxCallback.java:987)
03-28 07:35:10.646: W/System.err(24234): at android.os.Handler.handleCallback(Handler.java:725)
03-28 07:35:10.646: W/System.err(24234): at android.os.Handler.dispatchMessage(Handler.java:92)
03-28 07:35:10.646: W/System.err(24234): at android.os.Looper.loop(Looper.java:137)
03-28 07:35:10.646: W/System.err(24234): at android.app.ActivityThread.main(ActivityThread.java:5195)
03-28 07:35:10.646: W/System.err(24234): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 07:35:10.646: W/System.err(24234): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 07:35:10.646: W/System.err(24234): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
03-28 07:35:10.646: W/System.err(24234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
03-28 07:35:10.653: W/System.err(24234): at dalvik.system.NativeStart.main(Native Method)
REAL RAW JSON:
{"latitude":39.31667,"longitude":-120.13333,"timezone":"America/Los_Angeles","offset":-7,"currently":{"time":1364479080,"summary":"Overcast","icon":"cloudy","precipIntensity":0,"temperature":30.12,"windSpeed":0.83,"windBearing":350,"cloudCover":0.95,"humidity":0.93,"pressure":811.5,"visibility":9.5},"minutely":{"summary":"Overcast for the hour.","icon":"cloudy","data":[{"time":1364479080,"precipIntensity":0},{"time":1364479140,"precipIntensity":0},{"time":1364479200,"precipIntensity":0},{"time":1364479260,"precipIntensity":0},{"time":1364479320,"precipIntensity":0},{"time":1364479380,"precipIntensity":0},{"time":1364479440,"precipIntensity":0},{"time":1364479500,"precipIntensity":0},{"time":1364479560,"precipIntensity":0},{"time":1364479620,"precipIntensity":0},{"time":1364479680,"precipIntensity":0},{"time":1364479740,"precipIntensity":0},{"time":1364479800,"precipIntensity":0},{"time":1364479860,"precipIntensity":0},{"time":1364479920,"precipIntensity":0},{"time":1364479980,"precipIntensity":0},{"time":1364480040,"precipIntensity":0},{"time":1364480100,"precipIntensity":0},{"time":1364480160,"precipIntensity":0},{"time":1364480220,"precipIntensity":0},{"time":1364480280,"precipIntensity":0},{"time":1364480340,"precipIntensity":0},{"time":1364480400,"precipIntensity":0},{"time":1364480460,"precipIntensity":0},{"time":1364480520,"precipIntensity":0},{"time":1364480580,"precipIntensity":0},{"time":1364480640,"precipIntensity":0},{"time":1364480700,"precipIntensity":0},{"time":1364480760,"precipIntensity":0},{"time":1364480820,"precipIntensity":0},{"time":1364480880,"precipIntensity":0},{"time":1364480940,"precipIntensity":0},{"time":1364481000,"precipIntensity":0},{"time":1364481060,"precipIntensity":0},{"time":1364481120,"precipIntensity":0},{"time":1364481180,"precipIntensity":0},{"time":1364481240,"precipIntensity":0},{"time":1364481300,"precipIntensity":0},{"time":1364481360,"precipIntensity":0},{"time":1364481420,"precipIntensity":0},{"time":1364481480,"precipIntensity":0},{"time":1364481540,"precipIntensity":0},{"time":1364481600,"precipIntensity":0},{"time":1364481660,"precipIntensity":0},{"time":1364481720,"precipIntensity":0},{"time":1364481780,"precipIntensity":0},{"time":1364481840,"precipIntensity":0},{"time":1364481900,"precipIntensity":0},{"time":1364481960,"precipIntensity":0},{"time":1364482020,"precipIntensity":0},{"time":1364482080,"precipIntensity":0},{"time":1364482140,"precipIntensity":0},{"time":1364482200,"precipIntensity":0},{"time":1364482260,"precipIntensity":0},{"time":1364482320,"precipIntensity":0},{"time":1364482380,"precipIntensity":0},{"time":1364482440,"precipIntensity":0},{"time":1364482500,"precipIntensity":0},{"time":1364482560,"precipIntensity":0},{"time":1364482620,"precipIntensity":0}]},"hourly":{"summary":"Mostly cloudy later this morning.","icon":"partly-cloudy-day","data":[{"time":1364475600,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","precipIntensity":0,"temperature":29,"windSpeed":3.64,"windBearing":352,"cloudCover":0.77,"humidity":0.96,"pressure":810.5,"visibility":9.53},{"time":1364479200,"summary":"Overcast","icon":"cloudy","precipIntensity":0.001,"precipProbability":0.04,"precipType":"rain","temperature":30.16,"windSpeed":0.73,"windBearing":350,"cloudCover":0.96,"humidity":0.93,"pressure":811.53,"visibility":9.5},{"time":1364482800,"summary":"Overcast","icon":"cloudy","precipIntensity":0,"temperature":30.51,"windSpeed":3.27,"windBearing":347,"cloudCover":0.95,"humidity":0.91,"pressure":812.28,"visibility":7.52},{"time":1364486400,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":36.34,"windSpeed":4.14,"windBearing":344,"cloudCover":0.75,"humidity":0.82,"pressure":812.23,"visibility":8.62},{"time":1364490000,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":42.22,"windSpeed":5.82,"windBearing":286,"cloudCover":0.73,"humidity":0.72,"pressure":812.93,"visibility":9.44},{"time":1364493600,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":48.01,"windSpeed":6.85,"windBearing":281,"cloudCover":0.7,"humidity":0.64,"pressure":813.25,"visibility":10},{"time":1364497200,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":53.27,"windSpeed":8.03,"windBearing":279,"cloudCover":0.71,"humidity":0.55,"pressure":813.21,"visibility":10},{"time":1364500800,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.001,"precipProbability":0.02,"precipType":"rain","temperature":57.24,"windSpeed":10.16,"windBearing":273,"cloudCover":0.72,"humidity":0.5,"pressure":813.8,"visibility":10},{"time":1364504400,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.001,"precipProbability":0.04,"precipType":"rain","temperature":59.29,"windSpeed":11.04,"windBearing":270,"cloudCover":0.74,"humidity":0.46,"pressure":814.14,"visibility":10},{"time":1364508000,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.001,"precipProbability":0.06,"precipType":"rain","temperature":59.4,"windSpeed":11.98,"windBearing":266,"cloudCover":0.76,"humidity":0.46,"pressure":813.64,"visibility":10},{"time":1364511600,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.003,"precipProbability":0.1,"precipType":"rain","temperature":57.99,"windSpeed":12.46,"windBearing":263,"cloudCover":0.79,"humidity":0.48,"pressure":813.77,"visibility":10},{"time":1364515200,"summary":"Overcast","icon":"cloudy","precipIntensity":0.003,"precipProbability":0.22,"precipType":"rain","temperature":55.31,"windSpeed":12.07,"windBearing":264,"cloudCover":0.96,"humidity":0.52,"pressure":813.96,"visibility":10},{"time":1364518800,"summary":"Overcast","icon":"cloudy","precipIntensity":0.002,"precipProbability":0.08,"precipType":"rain","temperature":52.4,"windSpeed":10.37,"windBearing":261,"cloudCover":0.97,"humidity":0.57,"pressure":814.13,"visibility":10},{"time":1364522400,"summary":"Overcast","icon":"cloudy","precipIntensity":0.001,"precipProbability":0.05,"precipType":"rain","temperature":48.61,"windSpeed":8.01,"windBearing":261,"cloudCover":0.96,"humidity":0.63,"pressure":814.43,"visibility":10},{"time":1364526000,"summary":"Overcast","icon":"cloudy","precipIntensity":0,"temperature":44.99,"windSpeed":5.43,"windBearing":262,"cloudCover":0.95,"humidity":0.73,"pressure":815.11,"visibility":9.96},{"time":1364529600,"summary":"Overcast","icon":"cloudy","precipIntensity":0,"temperature":42.37,"windSpeed":3.94,"windBearing":260,"cloudCover":0.9,"humidity":0.79,"pressure":815.64,"visibility":9},{"time":1364533200,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.03,"precipType":"rain","temperature":39.84,"windSpeed":2.93,"windBearing":249,"cloudCover":0.68,"humidity":0.84,"pressure":820.38,"visibility":9.76},{"time":1364536800,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.03,"precipType":"rain","temperature":38.14,"windSpeed":2.1,"windBearing":241,"cloudCover":0.62,"humidity":0.86,"pressure":820.66,"visibility":10},{"time":1364540400,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0,"temperature":36.13,"windSpeed":1.38,"windBearing":342,"cloudCover":0.39,"humidity":0.89,"pressure":820.85,"visibility":9.7},{"time":1364544000,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0,"temperature":34.54,"windSpeed":1.87,"windBearing":253,"cloudCover":0.34,"humidity":0.89,"pressure":820.96,"visibility":9.7},{"time":1364547600,"summary":"Clear","icon":"clear-night","precipIntensity":0,"temperature":33.13,"windSpeed":1.3,"windBearing":353,"cloudCover":0.16,"humidity":0.91,"pressure":821.04,"visibility":9.58},{"time":1364551200,"summary":"Clear","icon":"clear-night","precipIntensity":0,"temperature":31.12,"windSpeed":1.84,"windBearing":150,"cloudCover":0.17,"humidity":0.93,"pressure":821.13,"visibility":9.75},{"time":1364554800,"summary":"Clear","icon":"clear-night","precipIntensity":0,"temperature":29.64,"windSpeed":1.31,"windBearing":0,"cloudCover":0.19,"humidity":0.93,"pressure":821.21,"visibility":9.82},{"time":1364558400,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0,"temperature":28.99,"windSpeed":1.86,"windBearing":138,"cloudCover":0.21,"humidity":0.93,"pressure":821.28,"visibility":9.91},{"time":1364562000,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0,"temperature":29.79,"windSpeed":1.26,"windBearing":6,"cloudCover":0.23,"humidity":0.89,"pressure":821.48,"visibility":10},{"time":1364565600,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":33.36,"windSpeed":2.27,"windBearing":26,"cloudCover":0.33,"humidity":0.82,"pressure":821.73},{"time":1364569200,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":36.61,"windSpeed":2.24,"windBearing":35,"cloudCover":0.38,"humidity":0.78,"pressure":821.94},{"time":1364572800,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":43.46,"windSpeed":2.8,"windBearing":41,"cloudCover":0.39,"humidity":0.69,"pressure":822.13},{"time":1364576400,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":51.61,"windSpeed":3.6,"windBearing":44,"cloudCover":0.38,"humidity":0.59,"pressure":822.29},{"time":1364580000,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0,"temperature":57.8,"windSpeed":4.21,"windBearing":45,"cloudCover":0.37,"humidity":0.52,"pressure":822.4},{"time":1364583600,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.001,"precipProbability":0.08,"precipType":"rain","temperature":61.78,"windSpeed":4.51,"windBearing":33,"cloudCover":0.38,"humidity":0.48,"pressure":822.34},{"time":1364587200,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.003,"precipProbability":0.2,"precipType":"rain","temperature":64.38,"windSpeed":4.66,"windBearing":9,"cloudCover":0.38,"humidity":0.46,"pressure":822.18},{"time":1364590800,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.004,"precipProbability":0.28,"precipType":"rain","temperature":66,"windSpeed":4.75,"windBearing":341,"cloudCover":0.39,"humidity":0.45,"pressure":822.02},{"time":1364594400,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.004,"precipProbability":0.26,"precipType":"rain","temperature":64.99,"windSpeed":4.89,"windBearing":310,"cloudCover":0.45,"humidity":0.45,"pressure":821.84},{"time":1364598000,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.003,"precipProbability":0.19,"precipType":"rain","temperature":62.44,"windSpeed":4.99,"windBearing":289,"cloudCover":0.53,"humidity":0.47,"pressure":821.67},{"time":1364601600,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.003,"precipProbability":0.14,"precipType":"rain","temperature":60.25,"windSpeed":5.01,"windBearing":276,"cloudCover":0.58,"humidity":0.48,"pressure":821.57},{"time":1364605200,"summary":"Mostly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.002,"precipProbability":0.1,"precipType":"rain","temperature":57.05,"windSpeed":4.46,"windBearing":266,"cloudCover":0.53,"humidity":0.53,"pressure":821.68},{"time":1364608800,"summary":"Partly Cloudy","icon":"partly-cloudy-day","precipIntensity":0.002,"precipProbability":0.07,"precipType":"rain","temperature":53.35,"windSpeed":3.67,"windBearing":257,"cloudCover":0.44,"humidity":0.61,"pressure":821.91},{"time":1364612400,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.002,"precipProbability":0.04,"precipType":"rain","temperature":50.18,"windSpeed":3.03,"windBearing":247,"cloudCover":0.38,"humidity":0.67,"pressure":822.13},{"time":1364616000,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.02,"precipType":"rain","temperature":47.87,"windSpeed":2.62,"windBearing":228,"cloudCover":0.39,"humidity":0.71,"pressure":822.37},{"time":1364619600,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.01,"precipType":"rain","temperature":46.27,"windSpeed":2.32,"windBearing":203,"cloudCover":0.43,"humidity":0.74,"pressure":822.61},{"time":1364623200,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0,"temperature":45.09,"windSpeed":2.14,"windBearing":186,"cloudCover":0.47,"humidity":0.75,"pressure":822.78},{"time":1364626800,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.01,"precipType":"rain","temperature":43.36,"windSpeed":2.28,"windBearing":182,"cloudCover":0.47,"humidity":0.77,"pressure":822.77},{"time":1364630400,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.03,"precipType":"rain","temperature":41.6,"windSpeed":2.58,"windBearing":339,"cloudCover":0.46,"humidity":0.78,"pressure":822.65},{"time":1364634000,"summary":"Partly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.001,"precipProbability":0.06,"precipType":"rain","temperature":40.18,"windSpeed":2.82,"windBearing":22,"cloudCover":0.47,"humidity":0.79,"pressure":822.52},{"time":1364637600,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.002,"precipProbability":0.16,"precipType":"rain","temperature":38.64,"windSpeed":2.88,"windBearing":47,"cloudCover":0.54,"humidity":0.8,"pressure":822.29},{"time":1364641200,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.004,"precipProbability":0.29,"precipType":"rain","temperature":37.19,"windSpeed":2.85,"windBearing":41,"cloudCover":0.64,"humidity":0.81,"pressure":822.03},{"time":1364644800,"summary":"Sprinkling","icon":"rain","precipIntensity":0.006,"precipProbability":0.37,"precipType":"rain","temperature":36.18,"windSpeed":2.84,"windBearing":35,"cloudCover":0.72,"humidity":0.82,"pressure":821.85},{"time":1364648400,"summary":"Mostly Cloudy","icon":"partly-cloudy-night","precipIntensity":0.005,"precipProbability":0.31,"precipType":"rain","temperature":36.61,"windSpeed":3.01,"windBearing":41,"cloudCover":0.72,"humidity":0.81,"pressure":821.79}]},"daily":{"summary":"Sprinkling off-and-on throughout the week; temperatures falling to 51° on Monday.","icon":"rain","data":[{"time":1364454000,"summary":"Mostly cloudy throughout the day.","icon":"partly-cloudy-day","sunriseTime":1364478709,"sunsetTime":1364523687,"precipIntensity":0.003,"precipType":"rain","temperatureMin":29,"temperatureMinTime":1364475600,"temperatureMax":59.4,"temperatureMaxTime":1364508000,"windSpeed":5.64,"windBearing":292,"cloudCover":0.79,"humidity":0.74,"pressure":813.03,"visibility":9.58},{"time":1364540400,"summary":"Partly cloudy throughout the day.","icon":"partly-cloudy-day","sunriseTime":1364565013,"sunsetTime":1364610146,"precipIntensity":0.004,"precipType":"rain","temperatureMin":28.99,"temperatureMinTime":1364558400,"temperatureMax":66,"temperatureMaxTime":1364590800,"windSpeed":3.04,"windBearing":332,"cloudCover":0.37,"humidity":0.69,"pressure":821.81,"visibility":9.78},{"time":1364626800,"summary":"Light rain throughout the day.","icon":"rain","sunriseTime":1364651317,"sunsetTime":1364696604,"precipIntensity":0.015,"precipType":"rain","temperatureMin":36.18,"temperatureMinTime":1364644800,"temperatureMax":59.63,"temperatureMaxTime":1364677200,"windSpeed":4.7,"windBearing":8,"cloudCover":0.73,"humidity":0.7,"pressure":819.1},{"time":1364713200,"summary":"Light rain throughout the day.","icon":"rain","sunriseTime":1364737622,"sunsetTime":1364783062,"precipIntensity":0.029,"precipType":"rain","temperatureMin":34.97,"temperatureMinTime":1364731200,"temperatureMax":52.75,"temperatureMaxTime":1364763600,"windSpeed":4.63,"windBearing":263,"cloudCover":0.97,"humidity":0.84,"pressure":815.54},{"time":1364799600,"summary":"Overcast throughout the day.","icon":"partly-cloudy-day","sunriseTime":1364823926,"sunsetTime":1364869521,"precipIntensity":0.005,"precipType":"rain","temperatureMin":31.91,"temperatureMinTime":1364817600,"temperatureMax":51.23,"temperatureMaxTime":1364860800,"windSpeed":4.52,"windBearing":244,"cloudCover":0.83,"humidity":0.83,"pressure":817.95},{"time":1364886000,"summary":"Sprinkling starting in the afternoon, continuing until evening.","icon":"rain","sunriseTime":1364910232,"sunsetTime":1364955979,"precipIntensity":0.007,"precipType":"rain","temperatureMin":30.72,"temperatureMinTime":1364904000,"temperatureMax":61.06,"temperatureMaxTime":1364940000,"windSpeed":3.68,"windBearing":229,"cloudCover":0.41,"humidity":0.77,"pressure":820.08},{"time":1364972400,"summary":"Mostly cloudy throughout the day.","icon":"partly-cloudy-day","sunriseTime":1364996537,"sunsetTime":1365042437,"precipIntensity":0.001,"precipType":"rain","temperatureMin":30.94,"temperatureMinTime":1364990400,"temperatureMax":64.17,"temperatureMaxTime":1365022800,"windSpeed":3.63,"windBearing":252,"cloudCover":0.38,"humidity":0.71,"pressure":819.81},{"time":1365058800,"summary":"Overcast in the morning.","icon":"partly-cloudy-night","sunriseTime":1365082843,"sunsetTime":1365128896,"precipIntensity":0.001,"precipType":"rain","temperatureMin":34.63,"temperatureMinTime":1365076800,"temperatureMax":42.52,"temperatureMaxTime":1365058800,"windSpeed":3.5,"windBearing":304,"cloudCover":0.92,"humidity":0.68,"pressure":815.82}]},"alerts":[{"title":"Special Weather Statement for Nevada, CA","expires":1364518800,"uri":"http://alerts.weather.gov/cap/wwacapget.php?x=CA124EF50E7030.SpecialWeatherStatement.124EF51C1F50CA.STOSPSSTO.bb8abdb52e14e02477a8d74f36621a9e"}],"flags":{"sources":["nwspa","isd","fnmoc","naefs","rap","cmc","gfs","nam","metar","lamp","darksky"],"isd-stations":["724880-23185","725846-93201","725846-99999","999999-23185","999999-53133"],"metar-stations":["KBLU","KTRK","KTVL"],"lamp-stations":["KBLU","KTRK","KTVL"],"darksky-stations":["KRGX"]}}
答案 0 :(得分:1)
获得真正的JSON后的简单答案:此时JSON中没有可见性键。无论出于何种原因,API都不会返回一个:
{
"time":1364565600,
"summary":"Partly Cloudy",
"icon":"partly-cloudy-day",
"precipIntensity":0,
"temperature":33.36,
"windSpeed":2.27,
"windBearing":26,
"cloudCover":0.33,
"humidity":0.82,
"pressure":821.73
},
而不是数据没有正确存储,错误(如printStackTrace
所示)会出现在这一行:
visibility = hourlyData.getString("visibility");
首次尝试从JSON中提取值时
答案 1 :(得分:0)
visibility = hourlyData.getString("visibility");
可见性不是字符串,而是JSON中的整数。