I could use some assistance. I am trying to deserialize a Json file and then add it to a list so I can drop it into a table within a C# application. I get part of my code to produce, but not the nested areas.
I want to count the total number of properties (shown as "features" in the json). I then want to list out the "attributes" for each property.
Any help would be awesome. -Rob
using System;
using System.Collections.Generic;
using Newtonsoft.Json;
using System.Net;
public class Program
{
public static void Main()
{
WebClient client = new WebClient();
string json = client.DownloadString("https://gis.nccde.org/agsserver/rest/services/CustomMaps/Ownership/MapServer/0/query?where=UPPER(SUBDIV)%20like%20'%25ENCLAVE%20AT%20ODESSA%25'&outFields=*&outSR=4326&f=json");
var myModel = JsonConvert.DeserializeObject<ParcelViewModel>(json);
Console.WriteLine("Top Level ID: " + myModel.displayFieldName);
Console.WriteLine("Property Count: " + myModel.features.Count);
int i = 0;
foreach (var fac in myModel.features)
{
i++;
Console.WriteLine(" ");
Console.WriteLine("Record Number: " + i);
Console.WriteLine("Address: " + fac.address);
Console.WriteLine("Owner: " + fac.CNTCTLAST);
Console.WriteLine(" ");
}
}
}
public class ParcelViewModel
{
public string displayFieldName { get; set; }
public string geometryType { get; set; }
public List<PropertyViewModel> features { get; set; }
}
public class PropertyViewModel
{
public string address { get; set; }
public string CNTCTLAST { get; set; }
}