issues loading winform with api rest
hi i got the following code:
but getting this:
Newtonsoft.Json.JsonSerializationException: 'Deserialized JSON type 'Newtonsoft.Json.Linq.JObject' is not compatible with expected type 'Newtonsoft.Json.Linq.JArray'. Path '', line 1, position 9636.'
what im missing?
8 Replies
reason you're rawdogging it with JObjects and JArrays instead of proper classes?
Any reason you're using the deprecated
WebRequest
instead of HttpClient
?
The error just tells you that the response contains a single object, but you're trying to get an array out of it
So, a quick fix would be using JObject
instead of JArray
But it'd be putting lipstick on a pigany reason i should use httpclient? is faster?
It's not deprecated
was a sample provided 😦
just learning
Well it's a bad sample then, just gonna say straight away
i see
i should redo all with httpclient then
Getting data from an API should be something more akin to
With
SomeDataClass
being a class that describes your JSON
Which you can even generate, if need be
$jsongenInstantly parse JSON in any language | quicktype
Whether you're using C#, Swift, TypeScript, Go, C++ or other languages, quicktype generates models and helper code for quickly and safely reading JSON in your apps. Customize online with advanced options, or download a command-line tool.
Convert JSON to C# Classes Online - Json2CSharp Toolkit
Convert any JSON object to C# classes online. Json2CSharp is a free toolkit that will help you generate C# classes on the fly.