M0286_Libro Curso
4: Web móvil en acción
public static String parseJSONResponse(String jsonResponse) { String timestamp = “”; JSONObject json; try { json = new JSONObject(jsonResponse); JSONObject result = json.
getJSONObject(“Result”);
timestamp = result.getString(“Timestamp”);
} catch (JSONException e) { e.printStackTrace(); } return timestamp;
} public static String getTimeStampFromYahooService() { String responseString = null; String baseurlString = “http://developer.yahooapis. RestClient client = new RestClient(baseurlString); client.AddParam(“appid”, “YahooDemo”); client.AddParam(“output”, “json”); try { client.Execute(RequestMethod. GET ); } catch (Exception e) { e.printStackTrace(); } responseString = client.getResponse(); return responseString; } Con el método UnixTimeStampToDateTime() realizamos la conversión del formato de tiempo que nos envía Yahoo a formato estándar. El método parseJSONResponse() parsea la cadena JSON recibida desde Yahoo y el método getTimeStampFromYahooService() es el que realiza la conexión y recoge los datos del Web Service . com/TimeService/V1/getTime”;
235
Made with FlippingBook - Online catalogs