I have an issue to deserialize a JSON to an object, i have been searching around and found the following 2 question
1:(Cannot deserialize the current JSON array (e.g. [1,2,3]) into type)
2:(Additional text encountered after finished reading JSON content:)
the Json response
[
{
"$id": "1",
"CompanyNumber": "000000",
"Address2": null,
"Address3": null,
"PostCode": "Some POst Code",
"County": "UNITED KINGDOM",
"AddressDescription": null,
"OutOfBusiness": false,
"StopDistributionIndicator": null,
"BranchIndicator": false,
"TelephoneNumber": "0000000",
"State": "",
"ConfidenceCode": 4,
"Number": "734125938",
"CompanyName": "Something LIMITED",
"Address1": " Lower Road",
"CountryCode": "GB",
"Town": "London"
},
{
"$id": "2",
"CompanyNumber": "000000",
"Address2": null,
"Address3": null,
"PostCode": "Some POst Code",
"County": "UNITED KINGDOM",
"AddressDescription": null,
"OutOfBusiness": false,
"StopDistributionIndicator": null,
"BranchIndicator": false,
"TelephoneNumber": "0000000",
"State": "",
"ConfidenceCode": 4,
"Number": "734125938",
"CompanyName": "Something LIMITED",
"Address1": " Lower Road",
"CountryCode": "GB",
"Town": "London"
},
{
"$id": "3",
"CompanyNumber": "000000",
"Address2": null,
"Address3": null,
"PostCode": "Some POst Code",
"County": "UNITED KINGDOM",
"AddressDescription": null,
"OutOfBusiness": false,
"StopDistributionIndicator": null,
"BranchIndicator": false,
"TelephoneNumber": "0000000",
"State": "",
"ConfidenceCode": 4,
"Number": "734125938",
"CompanyName": "Something LIMITED",
"Address1": " Lower Road",
"CountryCode": "GB",
"Town": "London"
}
]
My Class look like
[JsonProperty(PropertyName = "$id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "CompanyNumber")]
public string CompanyNumber { get; set; }
[JsonProperty(PropertyName = "Address2")]
public object Address2 { get; set; }
[JsonProperty(PropertyName = "Address3")]
public object Address3 { get; set; }
[JsonProperty(PropertyName = "PostCode")]
public string PostCode { get; set; }
[JsonProperty(PropertyName = "County")]
public string County { get; set; }
[JsonProperty(PropertyName = "AddressDescription")]
public object AddressDescription { get; set; }
[JsonProperty(PropertyName = "OutOfBusiness")]
public bool OutOfBusiness { get; set; }
[JsonProperty(PropertyName = "StopDistributionIndicator")]
public object StopDistributionIndicator { get; set; }
[JsonProperty(PropertyName = "BranchIndicator")]
public bool BranchIndicator { get; set; }
[JsonProperty(PropertyName = "TelephoneNumber")]
public string TelephoneNumber { get; set; }
[JsonProperty(PropertyName = "State")]
public string State { get; set; }
[JsonProperty(PropertyName = "ConfidenceCode")]
public int ConfidenceCode { get; set; }
[JsonProperty(PropertyName = "Number")]
public string Number { get; set; }
[JsonProperty(PropertyName = "CompanyName")]
public string CompanyName { get; set; }
[JsonProperty(PropertyName = "Address1")]
public string Address1 { get; set; }
[JsonProperty(PropertyName = "CountryCode")]
public string CountryCode { get; set; }
[JsonProperty(PropertyName = "Town")]
public string Town { get; set; }
when i try to follow the first question (which it is to remove the [] from the beginning and the end of the json response) it will work if the Json only contain information about one company like
[
{
"$id": "1",
"CompanyNumber": "000000",
"Address2": null,
"Address3": null,
"PostCode": "Some POst Code",
"County": "UNITED KINGDOM",
"AddressDescription": null,
"OutOfBusiness": false,
"StopDistributionIndicator": null,
"BranchIndicator": false,
"TelephoneNumber": "0000000",
"State": "",
"ConfidenceCode": 4,
"Number": "734125938",
"CompanyName": "Something LIMITED",
"Address1": " Lower Road",
"CountryCode": "GB",
"Town": "London"
}
]
when there is more information like the above Json i get the Error 'Additional text encountered after finished reading JSON content: and i am trying to deserilazing the json using the code below
dynamic x = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchResult>(t2, new Newtonsoft.Json.JsonSerializerSettings() { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore });
any help would be appreciated, because i am stuck