您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

136 行
2.6 KiB

  1. using System;
  2. namespace SUISS.Cloud.Boomlagoon.JSON
  3. {
  4. public class JSONValue
  5. {
  6. public JSONValue(JSONValueType type)
  7. {
  8. this.Type = type;
  9. }
  10. public JSONValue(string str)
  11. {
  12. this.Type = JSONValueType.String;
  13. this.Str = str;
  14. }
  15. public JSONValue(double number)
  16. {
  17. this.Type = JSONValueType.Number;
  18. this.Number = number;
  19. }
  20. public JSONValue(JSONObject obj)
  21. {
  22. if (obj == null)
  23. {
  24. this.Type = JSONValueType.Null;
  25. }
  26. else
  27. {
  28. this.Type = JSONValueType.Object;
  29. this.Obj = obj;
  30. }
  31. }
  32. public JSONValue(JSONArray array)
  33. {
  34. this.Type = JSONValueType.Array;
  35. this.Array = array;
  36. }
  37. public JSONValue(bool boolean)
  38. {
  39. this.Type = JSONValueType.Boolean;
  40. this.Boolean = boolean;
  41. }
  42. public JSONValue(JSONValue value)
  43. {
  44. this.Type = value.Type;
  45. switch (this.Type)
  46. {
  47. case JSONValueType.String:
  48. this.Str = value.Str;
  49. break;
  50. case JSONValueType.Number:
  51. this.Number = value.Number;
  52. break;
  53. case JSONValueType.Object:
  54. if (value.Obj != null)
  55. {
  56. this.Obj = new JSONObject(value.Obj);
  57. }
  58. break;
  59. case JSONValueType.Array:
  60. this.Array = new JSONArray(value.Array);
  61. break;
  62. case JSONValueType.Boolean:
  63. this.Boolean = value.Boolean;
  64. break;
  65. }
  66. }
  67. public JSONValueType Type { get; private set; }
  68. public string Str { get; set; }
  69. public double Number { get; set; }
  70. public JSONObject Obj { get; set; }
  71. public JSONArray Array { get; set; }
  72. public bool Boolean { get; set; }
  73. public JSONValue Parent { get; set; }
  74. public static implicit operator JSONValue(string str)
  75. {
  76. return new JSONValue(str);
  77. }
  78. public static implicit operator JSONValue(double number)
  79. {
  80. return new JSONValue(number);
  81. }
  82. public static implicit operator JSONValue(JSONObject obj)
  83. {
  84. return new JSONValue(obj);
  85. }
  86. public static implicit operator JSONValue(JSONArray array)
  87. {
  88. return new JSONValue(array);
  89. }
  90. public static implicit operator JSONValue(bool boolean)
  91. {
  92. return new JSONValue(boolean);
  93. }
  94. public override string ToString()
  95. {
  96. switch (this.Type)
  97. {
  98. case JSONValueType.String:
  99. return "\"" + this.Str + "\"";
  100. case JSONValueType.Number:
  101. return this.Number.ToString();
  102. case JSONValueType.Object:
  103. return this.Obj.ToString();
  104. case JSONValueType.Array:
  105. return this.Array.ToString();
  106. case JSONValueType.Boolean:
  107. return (!this.Boolean) ? "false" : "true";
  108. case JSONValueType.Null:
  109. return "null";
  110. default:
  111. return "null";
  112. }
  113. }
  114. }
  115. }