選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

59 行
1.4 KiB

  1. using System;
  2. using SUISS.Cloud.Boomlagoon.JSON;
  3. namespace SUISS.Cloud
  4. {
  5. public class JSONParse
  6. {
  7. public static int IntField(JSONObject json, string key, int defaultValue)
  8. {
  9. JSONValue value = json.GetValue(key);
  10. if (value == null || value.Type != JSONValueType.Number)
  11. {
  12. return defaultValue;
  13. }
  14. return (int)value.Number;
  15. }
  16. public static string StringField(JSONObject json, string key, string defaultValue)
  17. {
  18. JSONValue value = json.GetValue(key);
  19. if (value == null || value.Type != JSONValueType.String)
  20. {
  21. return defaultValue;
  22. }
  23. return value.Str;
  24. }
  25. public static double DoubleField(JSONObject json, string key, double defaultValue)
  26. {
  27. JSONValue value = json.GetValue(key);
  28. if (value == null || value.Type != JSONValueType.Number)
  29. {
  30. return defaultValue;
  31. }
  32. return value.Number;
  33. }
  34. public static long LongField(JSONObject json, string key, long defaultValue)
  35. {
  36. JSONValue value = json.GetValue(key);
  37. if (value == null || value.Type != JSONValueType.Number)
  38. {
  39. return defaultValue;
  40. }
  41. return (long)value.Number;
  42. }
  43. public static bool BoolField(JSONObject json, string key, bool defaultValue)
  44. {
  45. JSONValue value = json.GetValue(key);
  46. if (value == null || value.Type != JSONValueType.Boolean)
  47. {
  48. return defaultValue;
  49. }
  50. return value.Boolean;
  51. }
  52. }
  53. }