I'm trying to use a JSON stream using the following code(console example):
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);
}
}
}
}
}
This works perfect with almost all the information within the Json stream. BUT not for one item and that is the operator item witch is a string and always containing AND or OR. It's not possible to read that as a string but clearly is also defined as one.
I use a class generated by VisualStudio2019 to store the data. Here is a part of that class where the operator string is defined:
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; }
If I look at the Json data using http://jsoneditoronline.org/ it looks like this(again just a part):
"configurations": {
"CVE_data_version": "4.0",
"nodes": [
{
"operator": "OR",
"cpe_match": [
I need the information because if it OR or AND the data changes and I need to change my reading logic to read the extra information.
So how should I handle OR and AND strings in Json and use it so that I can make a decision in my program.
Thanks in advance