Skip to content

Commit 877e810

Browse files
committed
fix: JsonData.Remove() 中添加类型检查,防止 InvalidCastException
1 parent c108b30 commit 877e810

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Runtime/JsonData.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -828,9 +828,12 @@ public bool Remove(object obj)
828828
json = null;
829829
if(IsObject)
830830
{
831+
if (!(obj is string key))
832+
return false;
833+
831834
JsonData value = null;
832-
if (inst_object.TryGetValue((string)obj, out value))
833-
return inst_object.Remove((string)obj) && object_list.Remove(new KeyValuePair<string, JsonData>((string)obj, value));
835+
if (inst_object.TryGetValue(key, out value))
836+
return inst_object.Remove(key) && object_list.Remove(new KeyValuePair<string, JsonData>(key, value));
834837
else
835838
throw new KeyNotFoundException("The specified key was not found in the JsonData object.");
836839
}

0 commit comments

Comments
 (0)