Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7690403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:23:17+00:00 2026-05-31T20:23:17+00:00

I am trying to setup and consume an asp.net webapi rest application and consume

  • 0

I am trying to setup and consume an asp.net webapi rest application and consume it from another project.

I have made a simple helper to call the service like

public static string GetApiResponse(string apiMethod,Dictionary<string,string>queryString=null)
    {
        using (var client = new WebClient())
        {
            client.Headers.Add("ApiKey", ConfigurationManager.AppSettings["ApiKey"]);
            //add any query string values into the client
            if (queryString != null)
            {
                foreach (var query in queryString)
                {
                    client.QueryString.Add(query.Key, query.Value);
                }
            }
            try
            {
               string url = string.Format("{0}{1}", ConfigurationManager.AppSettings["ApiBaseUrl"],apiMethod);
               return(client.DownloadString(url));
            }
            catch (Exception ex)
            {
                return ex.Message;
            }

        }
    }

I am consuming it from my controller in a different project like

  private IEnumerable<CustomerModel> CustomerDetails()
    {
        var json = ApiRestHelper.GetApiResponse("Customer/Get");

        var data = JsonConvert.DeserializeObject<CustomerViewModel>(json, new JsonSerializerSettings
                                                                          {

                                                                          });

The returned data from the service is looking like

[{"CustomerId":"24a62bf8-7a4e-4837-859d-1f04dc983011","FirstName":"Joe","LastName":"Bloggs","StoreCustomerId":null}]

My CustomerViewModel is

 public class CustomerViewModel
{
    public IEnumerable<CustomerModel> Customers { get; set; }
}

I can see the data that is returned is an array and I am trying to convert it to the list. I get an error

Cannot deserialize JSON array (i.e. [1,2,3]) into type ‘WebApplication.Models.ViewModels.CustomerViewModel’.

The deserialized type must be an array or implement a collection interface like IEnumerable, ICollection or IList.

What do I need to change to allow the deserialization into my view model?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T20:23:18+00:00Added an answer on May 31, 2026 at 8:23 pm

    I was trying to do it wrong.

            var data = JsonConvert.DeserializeObject<List<CustomerModel>>(json, new JsonSerializerSettings
                                                                              {
    
                                                                              });
    

    Does the trick

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to setup a simple Thread/Poll table mapping. Here is what I have: Threads
Im trying to setup my asp.net mvc page like the following image: The header
Trying to setup a CodeIgniter based project for local development (LAMP stack), and once
I'm trying to setup CruiseControl.net at the moment. So far it works nice, but
I am trying to setup tracd for the project I am currently working on.
I am trying to setup a simple demo of activemq and mina. I edited
here's the setup for the project. I have a WCF Service that is hosted
Trying to setup plone2pdf in Plone 4. I have downloaded the Plone2pdf archive, extracted
Im trying to setup my django project on a staging server with nginx, virtualenv,
I am trying to implement performance testing on ActiveMQ, so have setup a basic

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.