I have a Json in file added to my project embedded resource. I want to read this file which contains a list of certain object and deserialize it.
I have following Json file:
[
{
"Status": 21,
"CustomerId": "e3633ccb-bbea-465d-9ce6-6c37e9c40e2e"
},
{
"Status": 20,
"CustomerId": "d02e2970-7c28-41b0-89f3-5276a97e12c9"
}
]
and following model:
public class CustomerStatus
{
public int Status { get; set; }
public string CustomerId { get; set; }
}
as I read the jSon file from resource, it is automatically in form of array of byte and as I convert it to string, it has \r\n and \t in it.
in my code I have following lines do achieve this but it fails:
var string customerdata = System.Text.Encoding.UTF8.GetString(myResources.CustomerStatus);
var data = JsonConvert.DeserializeObject<List<CustomerStatus>>(customerdata);
I receive this error: threw an exception of type 'Newtonsoft.Json.JsonReaderException' Message "Unexpected character encountered while parsing value: . Path '', line 0, position 0."
UPDATE:
following line also result the same issue:
var string customerdata = System.Text.Encoding.UTF8.GetString(myResources.CustomerStatus);
.Replace("\r\n", " ")
.Replace("\t", " ");
customerdata's first character's character code is 0xFEFF.