如何检查JSON字符串中是否存在特定密钥

时间:2019-04-15 01:42:58

标签: c# json ssis etl

我有以下json字符串数据作为输入:

string json="{"-1":0,"78":6,"79":6,"80":2,"81":16777215,"82":16777215,"83":1,"84":0,"85":0,"86":"2023/05/07","87":0,"88":0,"89":1,"90":1,"124":1,"16":5,"17":null,"18":null,"19":0,"20":2,"21":2000,"22":0,"23":0,"24":0,"25":0,"26":0,"109":0,"110":0,"29":0,"30":0,"31":0,"32":2000,"33":13710,"34":15710,"135":null}"

我想检查是否有任何键具有-1,以便它可以返回true或false。如何在C#中实现呢?我无法使用JSONobject命名空间。

1 个答案:

答案 0 :(得分:0)

您可以使用JavaSerializer或JSON.Net程序集解析Script组件内的JSON字符串,然后搜索键值。

如果JSON数据是形式化的且仅包含键和值,则可以搜索以下字符串"-1":,如果找到,则找到-1键。

if(json.contains("\"-1\":")){

//key found

}else{

// key not found

}