1 public static Update fromString(String json) {
2 try {
3 // Read json string
4 JSONObject obj = (JSONObject) new JSONParser().parse(json);
5 int buildNumber = ((Long) obj.get("buildNumber")).intValue();
6 URL download = new URL((String) obj.get("download"));
7 // Return cached update from json
8 return new Update(buildNumber, download, true);
9 } catch (IOException | ParseException ex) {
10 Log.e(TAG, "Invalid JSON object: " + json);
11 }
12 // Shouldn't be returned, but it may happen
13 return new Update(0, null, true);
14 }
15}
16