Skip to content

Instantly share code, notes, and snippets.

@Nek-

Nek-/error Secret

Last active August 5, 2020 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nek-/63423bba2ec7416bc59cad9756ceb0e5 to your computer and use it in GitHub Desktop.
Save Nek-/63423bba2ec7416bc59cad9756ceb0e5 to your computer and use it in GitHub Desktop.
Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'TotallySpy.Models.Collection`1[TotallySpy.Models.Variation]' because the type requires a JSON object (e.g. {"name":"value"}) to deserialize correctly.
To fix this error either change the JSON to a JSON object (e.g. {"name":"value"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List<T> that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.
Path '', line 1, position 1.
namespace Me.Models
{
class SomethingToTest
{
[JsonProperty("@id")]
public string id { get; set; }
}
}
{
"@id": "/foo/id",
"otherFields": [ {"mayBe": "Complexe"} ]
}
var client = new RestClient("https://localhost:8000");
client.UseNewtonsoftJson();
client.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true;
client.Authenticator = new JwtAuthenticator(this.Auth0Token);
var request = new RestRequest("variations?barcode="+barcode, RestSharp.DataFormat.Json);
var response = await client.GetAsync<SomethingToTest>(request);
Console.WriteLine(response.id);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment