@@ -64,18 +64,20 @@ public static String getCorrectJson(String s, boolean isArray) {
64
64
* @param json
65
65
* @return
66
66
*/
67
+ private static final Feature [] DEFAULT_FASTJSON_FEATURES = {Feature .OrderedField , Feature .AllowSingleQuotes , Feature .DisableCircularReferenceDetect , Feature .UseBigDecimal , Feature .UseObjectArray };
67
68
public static Object parse (Object obj ) {
68
69
int features = com .alibaba .fastjson .JSON .DEFAULT_PARSER_FEATURE ;
69
70
features |= Feature .OrderedField .getMask ();
70
71
try {
71
- return com .alibaba .fastjson .JSON .parse (obj instanceof String ? (String ) obj : toJSONString (obj ), features );
72
+ return com .alibaba .fastjson .JSON .parse (obj instanceof String ? (String ) obj : toJSONString (obj ), DEFAULT_FASTJSON_FEATURES );
72
73
} catch (Exception e ) {
73
74
Log .i (TAG , "parse catch \n " + e .getMessage ());
74
75
}
75
76
return null ;
76
77
}
78
+
77
79
/**obj转JSONObject
78
- * @param json
80
+ * @param obj
79
81
* @return
80
82
*/
81
83
public static JSONObject parseObject (Object obj ) {
@@ -89,16 +91,17 @@ public static JSONObject parseObject(Object obj) {
89
91
* @return
90
92
*/
91
93
public static JSONObject parseObject (String json ) {
92
- int features = com .alibaba .fastjson .JSON .DEFAULT_PARSER_FEATURE ;
93
- features |= Feature .OrderedField .getMask ();
94
- return parseObject (json , features );
94
+ return parseObject (json , DEFAULT_FASTJSON_FEATURES );
95
95
}
96
- /**json转JSONObject
96
+
97
+ /**
98
+ * json转JSONObject
99
+ *
97
100
* @param json
98
101
* @param features
99
102
* @return
100
103
*/
101
- public static JSONObject parseObject (String json , int features ) {
104
+ public static JSONObject parseObject (String json , Feature ... features ) {
102
105
try {
103
106
return com .alibaba .fastjson .JSON .parseObject (getCorrectJson (json ), JSONObject .class , features );
104
107
} catch (Exception e ) {
@@ -127,7 +130,7 @@ public static <T> T parseObject(String json, Class<T> clazz) {
127
130
try {
128
131
int features = com .alibaba .fastjson .JSON .DEFAULT_PARSER_FEATURE ;
129
132
features |= Feature .OrderedField .getMask ();
130
- return com .alibaba .fastjson .JSON .parseObject (getCorrectJson (json ), clazz , features );
133
+ return com .alibaba .fastjson .JSON .parseObject (getCorrectJson (json ), clazz , DEFAULT_FASTJSON_FEATURES );
131
134
} catch (Exception e ) {
132
135
Log .i (TAG , "parseObject catch \n " + e .getMessage ());
133
136
}
0 commit comments