I currently have a JSON File where the data is represented as:
{
"ClientAddress": [
{
"firstLine": "123 road one",
"city": "London"
},
{
"firstLine": "456 road two",
"city": "Los Angeles"
}
],
"ClientAddress": [
{
"firstLine": "92 kings road",
"city": "Dublin"
},
{
"firstLine": "34a Jim Road",
"city": "New York"
}
]
}
As I try to run this through my deserialiser, I have a return count of 4 but each object is null. I’m not quite sure where I’m going wrong with the mapping.
The following is my C# file:
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var jsonData = "{"ClientAddress":[{"firstLine":"123roadone","city":"London"},{"firstLine":"456roadtwo","city":"LosAngeles"}],"ClientAddress":[{"firstLine":"92kingsroad","city":"Dublin"},{"firstLine":"34aJimRoad","city":"NewYork"}]}";
var resultSet = JsonConvert.DeserializeObject<AddressRequest>(jsonData);
Console.ReadLine();
}
}
class AddressRequest
{
[JsonProperty("ClientAddress")]
public List<ClientAddress> ClientAddress { get; set; }
}
class ClientAddress
{
public List<Address> Addresses { get; set; }
}
class Address
{
[JsonProperty("firstLine")]
public string FirstLine { get; set; }
[JsonProperty("city")]
public string City { get; set; }
}
}