JSON.NET JToken Keys Are Case Sensitive?

前端 未结 2 549
谎友^
谎友^ 2021-01-12 09:46

I\'m having to perform some custom deserialization with JSON.NET and I just found that it\'s treating the key values in a JToken as case sensitive. Here\'s some code:

<
2条回答
  •  不知归路
    2021-01-12 09:56

    Convert JToken to JObject and use TryGetValue method of JObject in which you can specify String Comparision.

     var jObject = JToken.Load(reader) as JObject;
     JToken version;
     jObject.TryGetValue("version", StringComparison.OrdinalIgnoreCase, out version);
    

提交回复
热议问题