Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot deserialize the current JSON array #5

Open
Rajeshsomvanshi opened this issue Jan 21, 2022 · 1 comment
Open

Cannot deserialize the current JSON array #5

Rajeshsomvanshi opened this issue Jan 21, 2022 · 1 comment

Comments

@Rajeshsomvanshi
Copy link

Hi @bhrugen,

We are getting below error in BaseService.cs file but getting data properly in JSON.

Newtonsoft.Json.JsonSerializationException: 'Cannot deserialize the current JSON array (e.g. [1,2,3]) into type 'LSI.Web.Models.ResponseDto' 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 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.'

var apiRespnseDto = JsonConvert.DeserializeObject(apiContent); (Error Line)

One

Two

@manassantra
Copy link

           ##  YOU SHOULD TRY THIS WAY  ##
         ===================================
           
           apiResponse = await client.SendAsync(message);
           var apiContent = await apiResponse.Content.ReadAsStringAsync();
            var res = new ResponseMessegeBO
            {
                Result = apiContent
            };
            var response = JsonConvert.SerializeObject(res);
            var apiResponseDto = JsonConvert.DeserializeObject<T>(response);
            return apiResponseDto ;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants