Possible to search case-insensitive with JSONPath?

前端 未结 3 1251
清歌不尽
清歌不尽 2021-02-15 12:35

Using the SelectToken method of JSON.NET to select a token with JSONPath, I found no way to specifiy that the search should be case-insensitive.

E.g.

jso         


        
3条回答
  •  南旧
    南旧 (楼主)
    2021-02-15 13:27

    When I want to get a token and not have to worry about case I do this:

    var data = JObject.Parse(message.Data);
    var dataDictionary = new Dictionary(data.ToObject>(),
                                                            StringComparer.CurrentCultureIgnoreCase);
    

    If there are any nested structures I need to worry about then I have to do it again for those but that StringComparer means either dataDictionary["CampaignId"].ToString(); or dataDictionary["campaignId"].ToString(); will work and I get both.

提交回复
热议问题