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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T23:29:30+00:00 2026-05-29T23:29:30+00:00

I have a class, named DataItem, with three properties: Id, DataValue, and CreatedDateTime. The

  • 0

I have a class, named DataItem, with three properties: Id, DataValue, and CreatedDateTime. The properties are defined in the class in that order from top to bottom. This is also the order I’d like to see the properties in my JSON export. The problem is the properties in the DataItem object and in the JSON export are sorted in alphabetical order. Although there is nothing technically wrong with this format, it is a matter of readability.How do I control the order of properties in the JSON export?

I checked the dataItem wen instantiated and the properties are listed in alphabetical order. This is okay, I understand the potential usability issues of not sorting properties alphabetical.

public static List<DataItem>GetAllDataItems()
        {
            List<DataItem> dataItems = new List<DataItem>();

            SqlConnection conn = NetduinoDb.GetConnection();

            SqlCommand cmd = conn.CreateCommand();

            cmd.CommandText = "Select Id, DataValue, CreatedDateTime from XXX";
            cmd.CommandType = CommandType.Text;

            conn.Open();

            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                DataItem dataItem = new DataItem
                {
                    Id = reader["Id"].ToString(),
                    DataValue = reader["DataValue"].ToString(),
                    CreatedDateTime = reader["CreatedDateTime"].ToString()
                };

                dataItems.Add(dataItem);
            }

            reader.Close();
            conn.Close();


            return dataItems.ToList();
        }

This method is in my service implementation and returns the list of DataItems. I’m thinking I need to do something here but not sure what or how.

public List<DataItem> GetCollection()
{
    return DataRetriever.GetAllDataItems();
}
  • 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-29T23:29:32+00:00Added an answer on May 29, 2026 at 11:29 pm

    The DataContractJsonSerializer takes into consideration the DataMember attribute which has an Order property. You can use it to tell the serializer the order of the members you want serialized.

    [DataContract]
    class DataItem
    {
        [DataMember(Order = 1)]
        public string Id { get; set; }
    
        [DataMember(Order = 2)]
        public string DataValue { get; set; }
    
        [DataMember(Order = 3)]
        public string CreatedDateTime { get; set; }
    }
    

    Adjust the order as needed, but this is generally how it is done in WCF.

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

Sidebar

Related Questions

I have a class named baseClass. From this class I inherit a class names
I have a class named ValidableComboBox that derives directly from QComboBox . Every instance
I have a Class named Constants that contains all the constant variable in my
I have a class named Person and in this class is the property PersonName
I have a class named toto which I send to a function that does
I have a class named Graph, in this class I have a member named
I have a class named Entry declared like this: class Entry{ string Id {get;set;}
I have a class named PageBase inheriting from ASP.NET Page . I want to
I have a class named WhatClass that has List field in it. I need
I have a class named MyClass and I want this class to extend Graphics2D

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.