提交 a56a1f42 编写于 作者: B Blankj

see 01/29 log

上级 96e51ef5
* `19/01/28` [fix] KeyboardUtils#fixSoftInputLeaks didn't work on the device of HuaWei.
* `19/01/27` [upd] demo
* `19/01/29` [fix] LogUtils format json when json not start with '{'. Publish v1.23.3.
* `19/01/28` [fix] KeyboardUtils#fixSoftInputLeaks don't work on the device of HuaWei.
* `19/01/26` [fix] NetworkUtils#getNetworkType.
* `19/01/25` [add] CloneUtils, PermissionUtils support request permission of WRITE_SETTINGS and DRAW_OVERLAYS. Publish v1.23.2.
* `19/01/24` [add] BrightnessUtils and FlashlightUtils.
* `19/01/23` [add] Modify the demo of utilcode use kotlin. Publish v1.23.1.
......
......@@ -211,10 +211,15 @@ public final class JsonUtils {
public static String formatJson(final String json, final int indentSpaces) {
try {
if (json.startsWith("{")) {
return new JSONObject(json).toString(indentSpaces);
} else if (json.startsWith("[")) {
return new JSONArray(json).toString(indentSpaces);
for (int i = 0, len = json.length(); i < len; i++) {
char c = json.charAt(i);
if (c == '{') {
return new JSONObject(json).toString(indentSpaces);
} else if (c == '[') {
return new JSONArray(json).toString(indentSpaces);
} else if (!Character.isWhitespace(c)) {
return json;
}
}
} catch (JSONException e) {
e.printStackTrace();
......
......@@ -1030,10 +1030,15 @@ public final class LogUtils {
private static String formatJson(String json) {
try {
if (json.startsWith("{")) {
json = new JSONObject(json).toString(2);
} else if (json.startsWith("[")) {
json = new JSONArray(json).toString(2);
for (int i = 0, len = json.length(); i < len; i++) {
char c = json.charAt(i);
if (c == '{') {
return new JSONObject(json).toString(2);
} else if (c == '[') {
return new JSONArray(json).toString(2);
} else if (!Character.isWhitespace(c)) {
return json;
}
}
} catch (JSONException e) {
e.printStackTrace();
......
......@@ -35,7 +35,9 @@ public class CloneUtilsTest {
@Override
public String toString() {
return "{\"code\":" + code + ",\"message\":" + message + ",\"data\":" + data + "}";
return "{\"code\":" + primitive2String(code) +
",\"message\":" + primitive2String(message) +
",\"data\":" + primitive2String(data) + "}";
}
}
......@@ -51,7 +53,15 @@ public class CloneUtilsTest {
@Override
public String toString() {
return "{\"name\":" + name + ",\"gender\":" + gender + ",\"address\":" + address + "}";
return "{\"name\":" + primitive2String(name) +
",\"gender\":" + primitive2String(gender) +
",\"address\":" + primitive2String(address) + "}";
}
}
private static String primitive2String(final Object obj) {
if (obj == null) return "null";
if (obj instanceof CharSequence) return "\"" + obj.toString() + "\"";
return obj.toString();
}
}
\ No newline at end of file
......@@ -16,7 +16,7 @@ import java.util.Map;
*/
public class LogUtilsTest extends BaseTest {
private static final String JSON = "{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"JSON format\" , \"site\":\"http://tools.w3cschool.cn/code/JSON\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}";
private static final String JSON = "\r\n{\"tools\": [{ \"name\":\"css format\" , \"site\":\"http://tools.w3cschool.cn/code/css\" },{ \"name\":\"JSON format\" , \"site\":\"http://tools.w3cschool.cn/code/JSON\" },{ \"name\":\"pwd check\" , \"site\":\"http://tools.w3cschool.cn/password/my_password_safe\" }]}";
private static final String XML = "<books><book><author>Jack Herrington</author><title>PHP Hacks</title><publisher>O'Reilly</publisher></book><book><author>Jack Herrington</author><title>Podcasting Hacks</title><publisher>O'Reilly</publisher></book></books>";
private static final int[] ONE_D_ARRAY = new int[]{1, 2, 3};
private static final int[][] TWO_D_ARRAY = new int[][]{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}};
......@@ -166,10 +166,6 @@ public class LogUtilsTest extends BaseTest {
LogUtils.d((Object) TWO_D_ARRAY);
LogUtils.d(LIST);
LogUtils.d(MAP);
Object o = GsonUtils.fromJson(GsonUtils.toJson(LIST), GsonUtils.getListType(String.class));
System.out.println(o);
}
static class Person {
......@@ -193,5 +189,18 @@ public class LogUtilsTest extends BaseTest {
private static boolean equals(final Object o1, final Object o2) {
return o1 == o2 || (o1 != null && o1.equals(o2));
}
@Override
public String toString() {
return "{\"name\":" + primitive2String(name) +
",\"gender\":" + primitive2String(gender) +
",\"address\":" + primitive2String(address) + "}";
}
}
private static String primitive2String(final Object obj) {
if (obj == null) return "null";
if (obj instanceof CharSequence) return "\"" + obj.toString() + "\"";
return obj.toString();
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册