1
0

Fixing Json.GetValue()

This commit is contained in:
2023-05-11 18:12:45 +02:00
parent cb133aea0c
commit d755754198
3 changed files with 26 additions and 5 deletions

View File

@@ -146,13 +146,26 @@ namespace Newtonsoft.Json
if (lvlObj == null)
return defaultValue;
lvlObj = lvlObj[level];
string lvl = level;
if (lvlObj.Type == JTokenType.Object)
{
foreach (var prop in ((JObject)lvlObj).Properties())
{
if (prop.Name.Equals(lvl, System.StringComparison.OrdinalIgnoreCase))
{
lvl = prop.Name;
break;
}
}
}
lvlObj = lvlObj[lvl];
}
if (lvlObj == null)
return defaultValue;
return DeepConvert.ChangeType<T>(lvlObj is JValue ? ((JValue)lvlObj).Value : lvlObj.Value<object>());
return DeepConvert.ChangeType<T>(lvlObj is JValue lvlValue ? lvlValue.Value : lvlObj.Value<object>());
}
/// <summary>