Skip to content

Commit

Permalink
Client:同步adt版test工程至studio版
Browse files Browse the repository at this point in the history
  • Loading branch information
TommyLemon committed Sep 5, 2017
1 parent 1c26f95 commit 1143f2b
Show file tree
Hide file tree
Showing 17 changed files with 780 additions and 932 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,24 @@ public static String getCorrectJson(String s) {
public static String getCorrectJson(String s, boolean isArray) {
s = StringUtil.getTrimedString(s);
// if (isArray) {
// if (s.startsWith("\"")) {
// while (s.startsWith("\"")) {
// s = s.substring(1);
// }
// if (s.endsWith("\"")) {
// while (s.endsWith("\"")) {
// s = s.substring(0, s.length() - 1);
// }
// }
return s;//isJsonCorrect(s) ? s : null;
}

/**json转JSONObject
/**obj转JSONObject
* @param json
* @return
*/
public static JSONObject parseObject(Object obj) {
if (obj instanceof JSONObject) {
return (JSONObject) obj;
}
return parseObject(toJSONString(obj));
}
/**json转JSONObject
Expand Down Expand Up @@ -114,12 +117,16 @@ public static <T> T parseObject(JSONObject object, Class<T> clazz) {
* @return
*/
public static <T> T parseObject(String json, Class<T> clazz) {
try {
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
features |= Feature.OrderedField.getMask();
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), clazz, features);
} catch (Exception e) {
Log.i(TAG, "parseObject catch \n" + e.getMessage());
if (clazz == null) {
Log.e(TAG, "parseObject clazz == null >> return null;");
} else {
try {
int features = com.alibaba.fastjson.JSON.DEFAULT_PARSER_FEATURE;
features |= Feature.OrderedField.getMask();
return com.alibaba.fastjson.JSON.parseObject(getCorrectJson(json), clazz, features);
} catch (Exception e) {
Log.i(TAG, "parseObject catch \n" + e.getMessage());
}
}
return null;
}
Expand All @@ -131,6 +138,16 @@ public static <T> T parseObject(String json, Class<T> clazz) {
public static JSONArray parseArray(List<Object> list) {
return new JSONArray(list);
}
/**obj转JSONArray
* @param json
* @return
*/
public static JSONArray parseArray(Object obj) {
if (obj instanceof JSONArray) {
return (JSONArray) obj;
}
return parseArray(toJSONString(obj));
}
/**json转JSONArray
* @param json
* @return
Expand All @@ -157,10 +174,14 @@ public static <T> List<T> parseArray(JSONArray array, Class<T> clazz) {
* @return
*/
public static <T> List<T> parseArray(String json, Class<T> clazz) {
try {
return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json, true), clazz);
} catch (Exception e) {
Log.i(TAG, "parseArray catch \n" + e.getMessage());
if (clazz == null) {
Log.e(TAG, "parseArray clazz == null >> return null;");
} else {
try {
return com.alibaba.fastjson.JSON.parseArray(getCorrectJson(json, true), clazz);
} catch (Exception e) {
Log.i(TAG, "parseArray catch \n" + e.getMessage());
}
}
return null;
}
Expand Down
Loading

0 comments on commit 1143f2b

Please sign in to comment.