5 changed files with 179 additions and 12 deletions
-
47app/src/main/java/com/ouxuan/oxface/network/api/PadApiService.java
-
3app/src/main/java/com/ouxuan/oxface/orderOX/OrderVerificationResultActivity.java
-
89app/src/test/java/com/ouxuan/oxface/JsonParsingVerification.java
-
17app/src/test/java/com/ouxuan/oxface/OrderVerificationResultTest.java
-
35订单核销结果页面重构说明.md
@ -0,0 +1,89 @@ |
|||||
|
package com.ouxuan.oxface; |
||||
|
|
||||
|
import com.google.gson.Gson; |
||||
|
import com.google.gson.JsonElement; |
||||
|
import com.google.gson.JsonObject; |
||||
|
import com.ouxuan.oxface.network.api.PadApiService; |
||||
|
|
||||
|
/** |
||||
|
* 验证 JSON 数据解析的简单测试脚本 |
||||
|
*/ |
||||
|
public class JsonParsingVerification { |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
Gson gson = new Gson(); |
||||
|
|
||||
|
// 测试次卡核销数据(info 为字符串) |
||||
|
String peopleCardJson = "{\n" + |
||||
|
" \"order_no\": \"RC20250910155115457419\",\n" + |
||||
|
" \"start_time\": \"2025-09-10 15:51:16\",\n" + |
||||
|
" \"end_time\": \"4763-08-07 15:51:16\",\n" + |
||||
|
" \"order_type\": 1,\n" + |
||||
|
" \"project\": \"20230727测试\",\n" + |
||||
|
" \"number\": 1,\n" + |
||||
|
" \"v_code\": [\"250910159819\"],\n" + |
||||
|
" \"info\": \"平时\",\n" + |
||||
|
" \"success\": 0,\n" + |
||||
|
" \"pv_usage_duration\": 1,\n" + |
||||
|
" \"many_enter\": false\n" + |
||||
|
"}"; |
||||
|
|
||||
|
// 测试年月卡核销数据(info 为对象) |
||||
|
String monthlyCardJson = "{\n" + |
||||
|
" \"order_no\": \"MC20250908145253448493\",\n" + |
||||
|
" \"start_time\": \"2025-09-08 14:52:59\",\n" + |
||||
|
" \"end_time\": \"2025-10-08 14:52:59\",\n" + |
||||
|
" \"order_type\": 3,\n" + |
||||
|
" \"project\": \"可多次进出\",\n" + |
||||
|
" \"number\": 7,\n" + |
||||
|
" \"v_code\": [\"2509087910\"],\n" + |
||||
|
" \"info\": {\n" + |
||||
|
" \"card_no\": \"2509085314\",\n" + |
||||
|
" \"rest_number\": 5,\n" + |
||||
|
" \"status\": 1,\n" + |
||||
|
" \"verify_desc\": \"人脸验证\",\n" + |
||||
|
" \"verify_time\": \"2025-09-10 11:26:36\",\n" + |
||||
|
" \"verify_type\": 2\n" + |
||||
|
" },\n" + |
||||
|
" \"success\": 2,\n" + |
||||
|
" \"pv_usage_duration\": 0,\n" + |
||||
|
" \"many_enter\": false\n" + |
||||
|
"}"; |
||||
|
|
||||
|
try {\n" + |
||||
|
" // 测试次卡解析\n" + |
||||
|
" System.out.println(\"=== 测试次卡核销数据解析 ===\");\n" + |
||||
|
" PadApiService.VerifyOrderResult peopleCardResult = gson.fromJson(peopleCardJson, PadApiService.VerifyOrderResult.class);\n" + |
||||
|
" \n" + |
||||
|
" System.out.println(\"订单类型: \" + peopleCardResult.getOrderType());\n" + |
||||
|
" System.out.println(\"订单号: \" + peopleCardResult.getOrderNo());\n" + |
||||
|
" \n" + |
||||
|
" JsonElement peopleInfo = peopleCardResult.getInfo();\n" + |
||||
|
" if (peopleInfo != null && peopleInfo.isJsonPrimitive()) {\n" + |
||||
|
" System.out.println(\"Info(字符串): \" + peopleInfo.getAsString());\n" + |
||||
|
" System.out.println(\"辅助方法 getInfoAsString(): \" + peopleCardResult.getInfoAsString());\n" + |
||||
|
" }\n" + |
||||
|
" \n" + |
||||
|
" // 测试年月卡解析\n" + |
||||
|
" System.out.println(\"\\n=== 测试年月卡核销数据解析 ===\");\n" + |
||||
|
" PadApiService.VerifyOrderResult monthlyCardResult = gson.fromJson(monthlyCardJson, PadApiService.VerifyOrderResult.class);\n" + |
||||
|
" \n" + |
||||
|
" System.out.println(\"订单类型: \" + monthlyCardResult.getOrderType());\n" + |
||||
|
" System.out.println(\"订单号: \" + monthlyCardResult.getOrderNo());\n" + |
||||
|
" \n" + |
||||
|
" JsonElement monthlyInfo = monthlyCardResult.getInfo();\n" + |
||||
|
" if (monthlyInfo != null && monthlyInfo.isJsonObject()) {\n" + |
||||
|
" JsonObject cardInfo = monthlyInfo.getAsJsonObject();\n" + |
||||
|
" System.out.println(\"Info(对象)- 卡号: \" + cardInfo.get(\"card_no\").getAsString());\n" + |
||||
|
" System.out.println(\"Info(对象)- 剩余次数: \" + cardInfo.get(\"rest_number\").getAsInt());\n" + |
||||
|
" System.out.println(\"辅助方法 getCardNoFromInfo(): \" + monthlyCardResult.getCardNoFromInfo());\n" + |
||||
|
" }\n" + |
||||
|
" \n" + |
||||
|
" System.out.println(\"\\n✅ 所有测试通过!JSON 解析修复成功。\");\n" + |
||||
|
" \n" + |
||||
|
" } catch (Exception e) {\n" + |
||||
|
" System.err.println(\"❌ JSON 解析失败: \" + e.getMessage());\n" + |
||||
|
" e.printStackTrace();\n" + |
||||
|
" }\n" + |
||||
|
" }\n" + |
||||
|
"} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue