From 6169adbcdb705921a4635b4698b2dbda6f13c7f2 Mon Sep 17 00:00:00 2001 From: huyufei Date: Mon, 18 Mar 2024 14:13:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Json=20=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=E6=8A=A5=E9=94=99=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Runtime/Script/GuruAnalytics.cs | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs index 4af245e..829ee76 100644 --- a/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs +++ b/Runtime/GuruAnalytics/Runtime/Script/GuruAnalytics.cs @@ -5,6 +5,7 @@ using System.Globalization; using System.Linq; using System.Text; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; using UnityEngine; @@ -326,19 +327,29 @@ namespace Guru { //------- message send to unity ---------- Debug.Log($"{Tag} get callback errorInfo:\n{msg}"); - - var result = JsonConvert.DeserializeObject(msg); try { - if (result != null && result.action == ActionName) + var data = JsonConvert.DeserializeObject(msg); + if (data.TryGetValue("action", out var jKey)) { - if (result.data != null) + if (jKey.ToString() == ActionName) { - OnLoggerErrorEvent(result.data.code, result.data.msg); - return; + if (data.TryGetValue("code", out var jCode)) + { + int code = -1; + string message = msg; + int.TryParse(jCode.ToString(), out code); + + if (data.TryGetValue("msg", out var jMsg)) + { + message = jMsg.ToString(); + } + + OnLoggerErrorEvent(code, message); + return; + } } } - Debug.LogError($"{Tag} Parse callback Error"); } catch (Exception ex) @@ -374,30 +385,20 @@ namespace Guru Analytics.LogEvent("dev_audit", parameters, new Analytics.EventSetting() { EnableFirebaseAnalytics = true }); } - - + #endregion } - [Serializable] - internal class GuruLoggerCallback - { - public string action = ""; - public GuruLoggerErrorBody data; - } - [Serializable] - internal class GuruLoggerErrorBody - { - public int code; - public string msg; - } - + + /// /// 网络状态枚举 /// public enum AnalyticsCode { + Unknown = -1, + Network_Lost = 22, ERROR_API = 101,