添加trycatch
parent
a5a41ae777
commit
1c2c07bf0f
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections;
|
||||
|
|
@ -41,16 +42,29 @@ public class PlayerPrefsDataIO : DataIOBase
|
|||
}
|
||||
return jsonData;
|
||||
}
|
||||
|
||||
|
||||
public override void LoadToDic(string key, string jsonData, ref Dictionary<string, object> storageMap)
|
||||
{
|
||||
JObject jObj = JObject.Parse(jsonData);
|
||||
if (storageMap.TryGetValue(key, out object storageData))
|
||||
try
|
||||
{
|
||||
JsonConvert.PopulateObject(jObj.ToString(), storageMap[key], JsonSerializerData());
|
||||
JObject jObj = JObject.Parse(jsonData);
|
||||
|
||||
if (storageMap.TryGetValue(key, out object storageData))
|
||||
{
|
||||
JsonConvert.PopulateObject(jObj.ToString(), storageMap[key], JsonSerializerData());
|
||||
}
|
||||
}
|
||||
catch (JsonReaderException ex)
|
||||
{
|
||||
Debug.LogError($"JSON 解析异常: {ex.Message}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.LogError($"发生异常: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public override void Save()
|
||||
{
|
||||
PlayerPrefs.Save();
|
||||
|
|
|
|||
Loading…
Reference in New Issue