using System; using SUISS.Cloud.Boomlagoon.JSON; namespace SUISS.Cloud { public class JSONParse { public static int IntField(JSONObject json, string key, int defaultValue) { JSONValue value = json.GetValue(key); if (value == null || value.Type != JSONValueType.Number) { return defaultValue; } return (int)value.Number; } public static string StringField(JSONObject json, string key, string defaultValue) { JSONValue value = json.GetValue(key); if (value == null || value.Type != JSONValueType.String) { return defaultValue; } return value.Str; } public static double DoubleField(JSONObject json, string key, double defaultValue) { JSONValue value = json.GetValue(key); if (value == null || value.Type != JSONValueType.Number) { return defaultValue; } return value.Number; } public static long LongField(JSONObject json, string key, long defaultValue) { JSONValue value = json.GetValue(key); if (value == null || value.Type != JSONValueType.Number) { return defaultValue; } return (long)value.Number; } public static bool BoolField(JSONObject json, string key, bool defaultValue) { JSONValue value = json.GetValue(key); if (value == null || value.Type != JSONValueType.Boolean) { return defaultValue; } return value.Boolean; } } }