fix: 修复 Json 解析报错的问题

deeplink
胡宇飞 2024-03-18 14:13:20 +08:00
parent 25d644328c
commit 6169adbcdb
1 changed files with 23 additions and 22 deletions

View File

@ -5,6 +5,7 @@ using System.Globalization;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Newtonsoft.Json; using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine; using UnityEngine;
@ -326,19 +327,29 @@ namespace Guru
{ {
//------- message send to unity ---------- //------- message send to unity ----------
Debug.Log($"{Tag} get callback errorInfo:\n{msg}"); Debug.Log($"{Tag} get callback errorInfo:\n{msg}");
var result = JsonConvert.DeserializeObject<GuruLoggerCallback>(msg);
try try
{ {
if (result != null && result.action == ActionName) var data = JsonConvert.DeserializeObject<JObject>(msg);
if (data.TryGetValue("action", out var jKey))
{ {
if (result.data != null) if (jKey.ToString() == ActionName)
{ {
OnLoggerErrorEvent(result.data.code, result.data.msg); if (data.TryGetValue("code", out var jCode))
return; {
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"); Debug.LogError($"{Tag} Parse callback Error");
} }
catch (Exception ex) catch (Exception ex)
@ -375,29 +386,19 @@ namespace Guru
new Analytics.EventSetting() { EnableFirebaseAnalytics = true }); new Analytics.EventSetting() { EnableFirebaseAnalytics = true });
} }
#endregion #endregion
} }
[Serializable]
internal class GuruLoggerCallback
{
public string action = "";
public GuruLoggerErrorBody data;
}
[Serializable]
internal class GuruLoggerErrorBody
{
public int code;
public string msg;
}
/// <summary> /// <summary>
/// 网络状态枚举 /// 网络状态枚举
/// </summary> /// </summary>
public enum AnalyticsCode public enum AnalyticsCode
{ {
Unknown = -1,
Network_Lost = 22, Network_Lost = 22,
ERROR_API = 101, ERROR_API = 101,