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 7616729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T02:57:38+00:00 2026-05-31T02:57:38+00:00

I will start off by showing the JSON I would like to deserialize: {FleetsCollection:[{FleetId:2,Nickname:2007

  • 0

I will start off by showing the JSON I would like to deserialize:

{"FleetsCollection":[{"FleetId":2,"Nickname":"2007 Ninja ZX6R","PictureFileName":"jvmlfdaq.rkr2.jpg","AverageMpg":43.90925,"MaxMpg":47.945},{"FleetId":44,"Nickname":"Luminous Neptune","PictureFileName":"ochufm0c.ohm2.png","AverageMpg":29.4285,"MaxMpg":30.341}]}

This comes from a Fleets object which contains a list collection of Fleet objects like so:

public class Fleets
{
    private List<Fleet> fleets = new List<Fleet>();
}

The custom Fleet object is written as below:

public class Fleet
{
    public int FleetId { get; set; }
    public string Nickname { get; set; }
    public string PictureFileName { get; set; }
    public double AverageMpg { get; set; }
    public double MaxMpg { get; set; }
}

Finally, my deserialization code is shown here. I believe the questionable part here would be the few lines in the ConvertObject method:

    public class DataAccessState<T>
{
    public string Uri { get; set; }
    public T CallingClassType { get; set; }
    public string MethodToCall { get; set; }

    public DataAccessState(){}

    public DataAccessState(string uri, T callingClassType, string methodToCall)
    {
        Uri = uri;
        CallingClassType = callingClassType;
        MethodToCall = methodToCall;
    }
}

public static class DataAccessList<T>
{
    private static List<DataAccessState<T>> dataAccessStates = new List<DataAccessState<T>>();

    public static void Add(DataAccessState<T> dataAccessState)
    {
        dataAccessStates.Add(dataAccessState);
    }

    public static DataAccessState<T> FindAndRemove(string uri)
    {
        var dataAccessState = new DataAccessState<T>();

        foreach (var das in dataAccessStates)
        {
            if (das.Uri == uri)
                dataAccessState = das;
        }

        dataAccessStates.Remove(dataAccessState);

        return dataAccessState;
    }
}

public class RequestUpdateState
{
    public HttpWebRequest AsyncRequest { get; set; }
    public HttpWebResponse AsyncResponse { get; set; }
}

public class DataAccess<T>
{
    public void GetObject(string uriQuery, T callingClassType, string methodToCall)
    {
        //Create full uri
        var fullUri = "http://fuelizer.com/MobileJSON.svc/" + uriQuery;

        //Add calling type to list
        DataAccessState<T> dataAccessState = new DataAccessState<T>(fullUri, callingClassType, methodToCall);
        DataAccessList<T>.Add(dataAccessState);

        //Perform web service call
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(fullUri));
        RequestUpdateState requestState = new RequestUpdateState {AsyncRequest = request};

        request.BeginGetResponse(GetDataResponse, requestState);
    }

    private void GetDataResponse(IAsyncResult asyncResult)
    {
        try
        {
            RequestUpdateState requestState = (RequestUpdateState)asyncResult.AsyncState;
            HttpWebRequest request = requestState.AsyncRequest;
            requestState.AsyncResponse = (HttpWebResponse)request.EndGetResponse(asyncResult);
            Stream jsonObject = requestState.AsyncResponse.GetResponseStream();

            Deployment.Current.Dispatcher.BeginInvoke(() => ConvertObject(requestState.AsyncRequest.RequestUri.AbsoluteUri, jsonObject));
        }
        catch (WebException e){}
    }

    private void ConvertObject(string uri, Stream jsonObject)
    {
        var dataAccessState = DataAccessList<T>.FindAndRemove(uri);

        DataContractJsonSerializer ser = new DataContractJsonSerializer(dataAccessState.CallingClassType.GetType());
        var returnedObject = (T)ser.ReadObject(jsonObject);

        MethodInfo methodInfo = returnedObject.GetType().GetMethod(dataAccessState.MethodToCall);
        methodInfo.Invoke(returnedObject, null);
    }
}

What happens is I get a returned Fleets object with an empty list collection. This same code works with objects that do not have collections. So if I were just returning a Fleet object I would have no problem getting my response. It seems that this deserializer is not capable of deserializing an object which contains a list collection of custom types???

  • 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-31T02:57:39+00:00Added an answer on May 31, 2026 at 2:57 am

    Your ‘fleets’ property needs to be public and the names need to match up. Try it with this:

    public class Fleets
    {
        public List<Fleet> FleetsCollection = new List<Fleet>();
    }
    
    public class Fleet
    {
        public int FleetId { get; set; }
        public string Nickname { get; set; }
        public string PictureFileName { get; set; }
        public double AverageMpg { get; set; }
        public double MaxMpg { get; set; }
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like the text in the textarea to start off grey and turn
I'm trying to create a bookmarklet that will start off an AJAX call to
I will start off with the code... private static void File() { wixFile =
I will start off with a bit of introduction as to what I desire
I want my program to start off using a countdown timer that will be
I will start new PDA project on the windows mobile and compact framework 2.0
I will start by saying that I don't think what I want can be
As we all know Java program will start executing from the public static void
I have a .Net console App which using a scheduled event will start, call
I have an asp.net page that calls a dll that will start a long

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.