Unexpected character encountered while parsing value
Possibly you are not passing JSON to DeserializeObject
.
It looks like from File.WriteAllText(tmpfile,...
that type of tmpfile
is string
that contain path to a file. JsonConvert.DeserializeObject
takes JSON value, not file path - so it fails trying to convert something like @"c:\temp\fooo"
- which is clearly not JSON.
I solved the problem with these online tools:
- To check if the Json structure is OKAY: http://jsonlint.com/
- To generate my Object class from my Json structure: https://www.jsonutils.com/
The simple code:
RootObject rootObj= JsonConvert.DeserializeObject<RootObject>(File.ReadAllText(pathFile));
In my case, the file containing JSON string had BOM. Once I removed BOM the problem was solved.