问题描述
我正在尝试使用以下代码(控制台示例)使用 JSON 流:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Net.Http;
using System.Data;
using System.Net;
namespace jsontest
{
class Program
{
static void Main(string[] args)
{
using (var webClient = new WebClient())
{
string jsonString = webClient.DownloadString("https://services.nvd.nist.gov/rest/json/cves/1.0?cvssV3Severity=CRITICAL&resultsPerPage=30");
deserialiseJSON(jsonString);
}
void deserialiseJSON(string strjson)
{
var jPerson = JsonConvert.DeserializeObject<Rootobject>(strjson);
foreach(var num in jPerson.result.CVE_Items)
{
//Get the ID number and basescore -> Succes
Console.WriteLine("\nCVE ID : " + num.cve.CVE_data_Meta.ID + " CVSSv3 basescore : " + num.impact.baseMetricV3.cvssV3.basescore);
//Get the ID number and basescore -> Succes
Console.WriteLine("AndOr : " + num.configurations.nodes[0]._operator);
}
}
}
}
}
这适用于几乎所有 Json 流中的信息。 但不是针对一个项目,即运算符项目女巫是一个字符串,并且始终包含 AND 或 OR。 不可能将其作为字符串读取,但显然也定义为一个。
我使用 VisualStudio2019 生成的类来存储数据。 这是该类的一部分,其中定义了运算符字符串:
public class Configurations
{
public string CVE_data_version { get; set; }
public Node[] nodes { get; set; }
}
public class Node
{
public string _operator { get; set; }
public Cpe_Match[] cpe_match { get; set; }
public Child[] children { get; set; }
如果我使用 http://jsoneditoronline.org/ 查看 Json 数据,它看起来像这样(再次只是一部分):
"configurations": {
"CVE_data_version": "4.0","nodes": [
{
"operator": "OR","cpe_match": [
我需要这些信息,因为如果它发生 OR 或 AND 数据发生变化,我需要更改我的阅读逻辑以读取额外信息。
那么我应该如何处理 Json 中的 OR 和 AND 字符串并使用它,以便我可以在我的程序中做出决定。
提前致谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)