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.'
JsonConvert.DeserializeObject<string>(? why are you trying to decode json twice? Does the file contain a json string literal like"this is a string"?