精简代码
This commit is contained in:
parent
476ce02fc8
commit
7e2ad0c01d
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Jun 05 07:02:58 GMT 2025
|
||||
#Thu Jun 05 08:59:45 GMT 2025
|
||||
stageCount=8
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.8
|
||||
publishVersion=15.8.7
|
||||
buildCount=12
|
||||
buildCount=14
|
||||
baseBetaVersion=15.8.8
|
||||
|
@ -24,8 +24,7 @@ dependencies {
|
||||
api fileTree(dir: 'libs', include: ['*.jar'])
|
||||
// 网络连接类库
|
||||
api 'com.squareup.okhttp3:okhttp:4.4.1'
|
||||
api 'com.fasterxml.jackson.core:jackson-databind:2.18.2'
|
||||
// 添加Gson依赖
|
||||
// https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-databind
|
||||
|
||||
api 'com.google.code.gson:gson:2.10.1'
|
||||
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
#Created by .winboll/winboll_app_build.gradle
|
||||
#Thu Jun 05 07:02:58 GMT 2025
|
||||
#Thu Jun 05 08:59:45 GMT 2025
|
||||
stageCount=8
|
||||
libraryProject=libappbase
|
||||
baseVersion=15.8
|
||||
publishVersion=15.8.7
|
||||
buildCount=12
|
||||
buildCount=14
|
||||
baseBetaVersion=15.8.8
|
||||
|
@ -4,18 +4,14 @@ package cc.winboll.studio.libappbase.models;
|
||||
* @Author ZhanGSKen<zhangsken@188.com>
|
||||
* @Date 2025/06/05 11:26
|
||||
*/
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public class ResponseData {
|
||||
|
||||
public static final String STATUS_SUCCESS = "success";
|
||||
public static final String STATUS_ERROR = "error";
|
||||
|
||||
@JsonProperty("status")
|
||||
private String status;
|
||||
@JsonProperty("message")
|
||||
private String message;
|
||||
@JsonProperty("data")
|
||||
private UserInfoModel data;
|
||||
|
||||
public ResponseData() {
|
||||
|
@ -7,18 +7,14 @@ package cc.winboll.studio.libappbase.models;
|
||||
import android.util.JsonReader;
|
||||
import android.util.JsonWriter;
|
||||
import cc.winboll.studio.libappbase.BaseBean;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.IOException;
|
||||
|
||||
public class UserInfoModel extends BaseBean {
|
||||
|
||||
public static final String TAG = "UserInfoModel";
|
||||
|
||||
@JsonProperty("username")
|
||||
String username;
|
||||
@JsonProperty("password")
|
||||
String password;
|
||||
@JsonProperty("token")
|
||||
String token;
|
||||
|
||||
public UserInfoModel() {
|
||||
|
@ -1,46 +0,0 @@
|
||||
package cc.winboll.studio.libappbase.utils;
|
||||
|
||||
/**
|
||||
* @Author ZhanGSKen<zhangsken@188.com>
|
||||
* @Date 2025/06/05 11:09
|
||||
*/
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libappbase.models.ResponseData;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
public class JsonFormatter {
|
||||
public static final String TAG = "JsonFormatter";
|
||||
|
||||
/**
|
||||
* 将包含 Unicode 转义的 JSON 字符串转为可读中文
|
||||
* @param jsonStr 原始 JSON 字符串(如:{"status":"error","message":"\u672a\u63a5\u6536\u5230 JSON \u6570\u636e"})
|
||||
* @return 格式化后的中文消息字符串
|
||||
*/
|
||||
public static String formatUnicodeToChinese(String jsonStr) {
|
||||
try {
|
||||
// 1. 使用 Jackson 解析 JSON 到对象
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
ResponseData data = mapper.readValue(jsonStr, ResponseData.class);
|
||||
|
||||
// 2. 解码 Unicode 转义字符(如 \u672a 转为中文)
|
||||
String decodedMessage = URLDecoder.decode(data.getMessage(), "UTF-8");
|
||||
|
||||
// 3. 重新构建 JSON(可选:如需保留 JSON 格式)
|
||||
return "{\"status\":\"" + data.getStatus() + "\",\"message\":\"" + decodedMessage + "\"}";
|
||||
|
||||
} catch (Exception e) {
|
||||
LogUtils.d(TAG, e, Thread.currentThread().getStackTrace());
|
||||
return jsonStr; // 解析失败时返回原始字符串
|
||||
}
|
||||
}
|
||||
|
||||
// 示例用法
|
||||
/*public static void main(String[] args) {
|
||||
String rawJson = "{\"status\":\"error\",\"message\":\"\\u672a\\u63a5\\u6536\\u5230 JSON \\u6570\\u636e\"}";
|
||||
String formattedJson = formatUnicodeToChinese(rawJson);
|
||||
System.out.println("格式化前:" + rawJson);
|
||||
System.out.println("格式化后:" + formattedJson);
|
||||
}*/
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user