c# - 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 是否在文件中。有人能帮我吗?
解决方案
尝试这个 :
var result = datiJson.Any(p=> p.ip.Equals(myip));
推荐阅读
- javascript - 使组件贴在屏幕上并显示消息。反应
- php - 使用 SLIM 3 和 Eloquent 保存应用程序/json
- r - 在 R 中,在不同数据框中具有相同名称的列之间分别应用一个函数
- reactjs - 找不到 React js App throwing @babel/preset-es2015
- r - R:“plotmath”在使用 Computer Modern 字体时会产生额外的空白
- html - 如何让我的主图片覆盖下面的标头和按钮部分
- vb.net - 在 POS 热敏打印机上打印光栅图像时出现问题
- curl - 使用 cURL 命令触发我的 Jenkins 构建作业
- r - 分析 R 中的多项选择值 - 获取变量的频率计数
- hive - 如何删除 HIVE 表中的多个分区