我有以下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命名空间。
答案 0 :(得分:0)
您可以使用JavaSerializer或JSON.Net程序集解析Script组件内的JSON字符串,然后搜索键值。
如果JSON数据是形式化的且仅包含键和值,则可以搜索以下字符串"-1":
,如果找到,则找到-1
键。
if(json.contains("\"-1\":")){
//key found
}else{
// key not found
}