Java tutorial
//package com.java2s; import org.json.JSONObject; public class Main { public static float getJsonFloatValue(JSONObject jsonObject, String key, float defaultValue) { try { if (jsonObject != null && jsonObject.has(key)) { return Float.valueOf(jsonObject.getString(key)); } } catch (Exception e) { return defaultValue; } return defaultValue; } }