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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:47:03+00:00 2026-06-09T21:47:03+00:00

What is the best way to create a C# class that can be serialized

  • 0

What is the best way to create a C# class that can be serialized to as:

marks:          [
             { c: [57.162499, 65.54718], // latitude, longitude - this type of coordinates works only for World Map
               tooltip: 'Tyumen - Click to go to http://yahoo.com', // text for tooltip
               attrs: {
                        href: 'http://yahoo.com',            // link
                        src:  '/markers/pin1_red.png'        // image for marker
                       }
             },
             { xy: [50, 120], // x-y coodinates - works for all maps, including World Map
               tooltip: 'This is London! Click to go to http://london.com',
               attrs: {
                        href: 'http://yahoo.com',            // link
                        src:  '/markers/pin1_yellow.png'     // image for marker
                       }
             }
            ]

In above code we assign either assign ‘c’ or ‘xy’ but not both at the same time.
I’m using Newtonsoft.Json.
The only thing I want is a C# class that can be serialized to above code.

  • 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-06-09T21:47:04+00:00Added an answer on June 9, 2026 at 9:47 pm

    The class looks like this:

    [Serializable]
    public class Marks
    {
        public List<latlon> marks = new List<latlon>();
    }
    
    public class latlon
    {
        public double[] c;
        public int[] xy;
        public string tooltip;
        public attributes attrs;
    
        public latlon (double lat, double lon)
        {
            c = new double[] { lat, lon };
        }
        public latlon (int x, int y)
        {
            xy = new int[] { x, y };
        }
    }
    
    public class attributes
    {
        public string href;
        public string src;
    }
    

    The code to test it looks like this:

    string json;
    
    Marks obj = new Marks();
    latlon mark = new latlon(57.162, 65.547)
        {
            tooltip = "Tyumen - Click to go to http://yahoo.com",
            attrs = new attributes()
            {
                href = "http://yahoo.com",
                src = "/markers/pin1_red.png"
            }
        };
    
    obj.marks.Add(mark);
    
    mark = new latlon(50, 120)
        {
            tooltip = "This is London! Click to go to http://london.com",
            attrs = new attributes()
            {
                href = "http://yahoo.com",
                src = "/markers/pin1_yellow.png"
            }
        };
    
    obj.marks.Add(mark);
    
    //serialize to JSON, ignoring null elements
    json = JsonConvert.SerializeObject(obj, Formatting.None, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out the best way to create a class that can
What is the best way to create a custom UIView that I can consume
What would be the best way to create an array that can have an
What's the best way to create a model in Ruby on Rails that doesn't
Is there a good way to create a form in VB6 that can easily
What is best way to create a blinking image animation in wp7? Is there
What is the best way to create databases on C# application, I mean by
What is the best way to create multi-language database? To create localized table for
What is the best way to create a unique id column for table records
What is the best way to create a 'global event' in flex/actionscript - preferably

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.