Back to project page Common-Library.
The source code is released under:
Apache License
If you think the Android project Common-Library listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.morgan.library.net; //from w ww . jav a 2 s .c o m import org.json.JSONException; import org.json.JSONObject; import com.morgan.library.model.NetResult; import com.morgan.library.model.Weather; import com.morgan.library.model.WeatherType; import com.morgan.library.utils.Logger; /** * ???????????????json?????????VO??? * * @author Morgan.Ji * */ public class JsonUtils { public static final String TAG = JsonUtils.class.getName(); public static final String JSON_PARSE_ERROR_MESSAGE = "Json?????"; public static final int JSON_PARSE_ERROR_CODE = -1; public static void JsonToWeather(NetResult<Weather> result) { try { JSONObject jsonObject = new JSONObject(result.getResponseMessage()); if (jsonObject.getJSONArray("weather").length() > 0) { Weather weather = new Weather(); weather.setType(WeatherType.typeOf(jsonObject .getJSONArray("weather").getJSONObject(0) .getString("icon"))); weather.setTempature((int) (jsonObject.getJSONObject("main") .getDouble("temp") - 273.15)); result.setObject(weather); } } catch (JSONException e) { Logger.e(TAG, "weather data parase error " + e.getMessage()); result.setStatusCode(JSON_PARSE_ERROR_CODE); result.setErrorMessage(JSON_PARSE_ERROR_MESSAGE); } } }