首页 > 解决方案 > c#从json文件中搜索数据

问题描述

我的站点中有一个 json 文件。我希望我的 c# 脚本读取 json 文件并搜索我的 ip 是否在文件中。这是我的 json 文件:

[    
    { 
        "licenzaAttiva":true, 
        "webhook":"",
         "nomeServer": "Name of the server", 
         "idDiscordCliente": "Id Discord", 
         "nomeDiscordCliente": "My Name", 
         "ip": "my ip", 
         "licenza": "license"
    },
    { 
        "licenzaAttiva":true, 
        "webhook":"",
         "nomeServer": "Name of the server", 
         "idDiscordCliente": "Id Discord", 
         "nomeDiscordCliente": "My Name", 
         "ip": "my ip", 
         "licenza": "license"
    },
    { 
        "licenzaAttiva":true, 
        "webhook":"",
         "nomeServer": "Name of the server", 
         "idDiscordCliente": "Id Discord", 
         "nomeDiscordCliente": "My Name", 
         "ip": "my ip", 
         "licenza": "license"
    }
]

这是我在 C# 中的课程

public class Dati
{
    public string webhook { get; set; }
    public string nomeServer { get; set; }
    public string idDiscordCliente { get; set; }
    public string nomeDiscordCliente { get; set; }
    public string ip { get; set; }
    public string licenza { get; set; }
    public bool licenzaAttiva { get; set; }

}

这是我的代码

public static void Read()
{
   string site = "";
                WebClient wc = new WebClient();
                string data = wc.DownloadString(site);

                var datiJson = JsonConvert.DeserializeObject<List<Dati>>(data);
                string myip = "myip";
}

现在我希望我的脚本将 json 文件读入我的站点并搜索变量 myip 是否在文件中。有人能帮我吗?

标签: c#

解决方案


尝试这个 :

var result = datiJson.Any(p=> p.ip.Equals(myip));  

推荐阅读