[Solved] NewtonSoft Json Invalid Cast Exception


You need to use the generic overload JsonSerializer.Deserialize<T>()

var root = serializer.Deserialize<API_Json_Special_Feeds.RootObject>(jsonTextReader);

Unlike files generated by BinaryFormatter, JSON files generally do not include c# type information, so it’s necessary for the receiving system to specify the expected type.

(There are extensions to the JSON standard in which c# type information can be included in a JSON file — e.g. Json.NET’s TypeNameHandling — but it is still necessary to deserialize the JSON to an appropriate explicit base class.)

See Deserialize JSON from a file for another example of deserializing a strongly typed c# object from a stream.

1

solved NewtonSoft Json Invalid Cast Exception