org.json.simple.JSONobject get integer code example

Example: org.json.simple.JSONobject get integer

public static Update fromString(String json) {
    try {
      // Read json string
      JSONObject obj = (JSONObject) new JSONParser().parse(json);
      int buildNumber = ((Long) obj.get("buildNumber")).intValue();
      URL download = new URL((String) obj.get("download"));
      // Return cached update from json
      return new Update(buildNumber, download, true);
    } catch (IOException | ParseException ex) {
      Log.e(TAG, "Invalid JSON object: " + json);
    }
    // Shouldn't be returned, but it may happen
    return new Update(0, null, true);
  }
}

Tags:

Misc Example