1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
using System;
using System.Collections.Generic;
using XUtliPoolLib;
public class JsonUtil
{
public static float ParseFloat(object val, float defVal = 0f)
{
return (val == null) ? defVal : float.Parse(val.ToString());
}
public static int ParseInt(object val, int defVal = 0)
{
return (val == null) ? defVal : int.Parse(val.ToString());
}
public static bool ParseBool(object val, bool defVal = false)
{
bool flag = val == null;
bool result;
if (flag)
{
result = defVal;
}
else
{
try
{
result = (JsonUtil.ParseInt(val, defVal ? 1 : 0) != 0);
}
catch (Exception)
{
try
{
result = bool.Parse(val.ToString());
}
catch (Exception)
{
result = defVal;
}
}
}
return result;
}
public static DateTime ParseDateTime(object val)
{
return DateTime.Parse(val.ToString());
}
public static string ReadString(IDictionary<string, object> dic, string key, string defVal = "")
{
bool flag = dic != null && dic.ContainsKey(key);
string result;
if (flag)
{
result = ((dic[key] == null) ? defVal : dic[key].ToString());
}
else
{
result = defVal;
}
return result;
}
public static int ReadInt(IDictionary<string, object> dic, string key, int defVal = 0)
{
bool flag = dic != null && dic.ContainsKey(key);
int result;
if (flag)
{
result = JsonUtil.ParseInt(dic[key], defVal);
}
else
{
result = defVal;
}
return result;
}
public static bool ReadBool(IDictionary<string, object> dic, string key, bool defVal = false)
{
bool flag = dic != null && dic.ContainsKey(key);
bool result;
if (flag)
{
result = JsonUtil.ParseBool(dic[key], defVal);
}
else
{
result = defVal;
}
return result;
}
public static float ReadFloat(IDictionary<string, object> dic, string key, float defVal = 0f)
{
bool flag = dic != null && dic.ContainsKey(key);
float result;
if (flag)
{
result = JsonUtil.ParseFloat(dic[key], defVal);
}
else
{
result = defVal;
}
return result;
}
public static DateTime ReadDateTime(IDictionary<string, object> dic, string key)
{
return JsonUtil.ReadDateTime(dic, key, new DateTime(1, 1, 1, 0, 0, 0));
}
public static DateTime ReadDateTime(IDictionary<string, object> dic, string key, DateTime defVal)
{
bool flag = dic != null && dic.ContainsKey(key);
if (flag)
{
try
{
return JsonUtil.ParseDateTime(dic[key]);
}
catch (Exception ex)
{
XSingleton<XDebug>.singleton.AddErrorLog(ex.Message, null, null, null, null, null);
return defVal;
}
}
return defVal;
}
public static string ListToJsonStr(List<string> list)
{
bool flag = list == null || list.Count < 1;
string result;
if (flag)
{
result = "[]";
}
else
{
bool flag2 = true;
string text = "[";
foreach (string str in list)
{
bool flag3 = flag2;
if (flag3)
{
flag2 = false;
}
else
{
text += ",";
}
text += str;
}
text += "]";
result = text;
}
return result;
}
}
|