I am getting a JSON file in the format below which i am trying to consume and upload to SQL Server, I can upload most data except for any key with spaces in the name, like below Location (Last Level), I have 36 records in the JSON file and SSIS created 36 records in the SQL table but Location (Last Level) is blank, if I Country just to test it works and populate the table with correct values, I am only interested in Location (Last Level):
"records": [
{
"Location (Last Level)": "Calgary",
"Country": "Canada"
},
{
"Location (Last Level)": "Coconut Creek",
"Country": "United States"
},
I created a class for this:
namespace SC_0fc0e19fc563441a96856fc8e8911872
{
public class LocAPI
{
public string LocationLastLevel { get; set; }
}
public class Root
{
public List<LocAPI> records { get; set; }
}
}
I am not sure how do I consume or refer to JSON keys with spaces in the name like Location (Last Level). Any help appreciated.
Thanks
Update: I have change the class a little bit based on another thread but still didnt work:
using System.Text.Json.Serialization;
namespace SC_0fc0e19fc563441a96856fc8e8911872
{
public class LocAPI
{
[JsonPropertyName("Location (Last Level)")]
public string LocationLastLevel { get; set; }
}
public class Root
{
public List<LocAPI> records { get; set; }
}
}
Main:
var response = client.GetAsync(APIUrl).Result;
if (response.IsSuccessStatusCode)
{
var result = response.Content.ReadAsStringAsync().Result;
Root loc = new JavaScriptSerializer().Deserialize<Root>(result);
foreach (var item in loc.records)
{
LocationAPIBuffer.AddRow();
LocationAPIBuffer.Location = item.LocationLastLevel;
}