I have the following JSON Code retrieved from: https://urlscan.io/api/v1/search/?q=page.domain:google.nl&size=1
{
"results": [
{
"task": {
"visibility": "public",
"method": "automatic",
"domain": "secureauverificationn.de",
"apexDomain": "secureauverificationn.de",
"time": "2022-07-12T09:01:23.794Z",
"source": "certstream-suspicious",
"uuid": "01a2f1ac-97c5-4377-8d95-b77095e6e78f",
"url": "https://secureauverificationn.de"
},
"stats": {
"uniqIPs": 6,
"uniqCountries": 1,
"dataLength": 493720,
"encodedDataLength": 170314,
"requests": 11
},
"page": {
"country": "DE",
"server": "gws",
"redirected": "off-domain",
"ip": "2a00:1450:4001:82f::2003",
"mimeType": "text/html",
"title": "Google",
"url": "https://www.google.nl/",
"tlsValidDays": 83,
"tlsAgeDays": 35,
"tlsValidFrom": "2022-06-06T10:32:16.000Z",
"domain": "www.google.nl",
"umbrellaRank": 8162,
"apexDomain": "google.nl",
"asnname": "GOOGLE, US",
"asn": "AS15169",
"tlsIssuer": "GTS CA 1C3",
"status": "200"
},
"_id": "01a2f1ac-97c5-4377-8d95-b77095e6e78f",
"sort": [
1657616483794,
"01a2f1ac-97c5-4377-8d95-b77095e6e78f"
],
"result": "https://urlscan.io/api/v1/result/01a2f1ac-97c5-4377-8d95-b77095e6e78f/",
"screenshot": "https://urlscan.io/screenshots/01a2f1ac-97c5-4377-8d95-b77095e6e78f.png"
}
],
"total": 10000,
"took": 13,
"has_more": true
}
I want to get the value inside the results array:
"result": "https://urlscan.io/api/v1/result/01a2f1ac-97c5-4377-8d95-b77095e6e78f/",
This is the code I already have, but I stumble on the GetProperty because the next property is an array.
public static async Task<String> GetSearchResults(string url)
{
url = url.Replace("http://", "").Replace("https://", "");
string finalurl = "https://urlscan.io/api/v1/search/?q=page.domain:" + url + "&size=1";
var options = new RestClientOptions(finalurl)
{
ThrowOnAnyError = true,
Timeout = -1
};
var client = new RestClient(options);
var request = new RestRequest(finalurl, Method.Get);
RestResponse response = await client.ExecuteAsync(request);
String output = response.Content;
var JsonObject = JsonDocument.Parse(output);
var RootElement = JsonObject.RootElement;
var NewObject = RootElement.GetProperty("results").ToString();
Console.WriteLine(NewObject);
return output;
}
My question is how to retrieve the value from the nested array in the most simple way. I do not want to use Newtonsoft as I am using the System.Text.Json library.
What I do want is the following:
- Get the result value and save it to a string the easiest way possible
- A working example eventually that either iterates through an array or gets the values inside an array with system.text.json