I have a JSON file like below
{
"Valid": true
}
And the following model
public class Account
{
public bool Valid { get; set; }
public Account()
{
Valid = true;
}
}
When running the following code to deserialize
public static void JsonDeserializeTest(Type datatype, string filePath)
{
Account account = JsonConvert.DeserializeObject<Account>(JsonConvert.DeserializeObject<string>(File.ReadAllText(filePath)));
}
I'm receiving the following error:
Newtonsoft.Json.JsonReaderException: 'Unexpected character encountered while parsing value: {. Path '', line 1, position 1.'
You have to write your code just like this:
public static void JsonDeserializeTest(Type datatype, string filePath)
{
Account account = JsonConvert.DeserializeObject<Account>
(File.ReadAllText(filePath));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With