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

  • Home
  • SEARCH
  • 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 6737403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:14:41+00:00 2026-05-26T11:14:41+00:00

I am currently looking into using WCF for REST services. A problem I ran

  • 0

I am currently looking into using WCF for REST services. A problem I ran into is serializing results that are dictionaries. I used the wrapper class suggested in this post to serialize a dictionary consisting of string represented dates (e.g. “20.10.2011”) and bools. When I test the result I see this:

{
    "DeparturesResult":
    {
        "_x0032_1.10.2011":true,
        "_x0032_4.10.2011":true,
        "_x0032_6.10.2011":true,
        "_x0032_8.10.2011":true,
        "_x0033_1.10.2011":true
    }
}

..the first character in every key is written out as a UTF-8 code. I don’t encounter this problem if I prepend the string with a letter. (e.g. d21.10.2011)

Here is the code I am using to serialize the dictionary:
public class FlService : IFlService
{
#region IFlService Members

    public AjaxDictionary<string, bool> Departures(string from, string to, string portFrom, string portTo)
    {
        var startDate = DateTime.Today; // DateTime.ParseExact(from, "dd.MM.yyyy", null);
        var endDate = DateTime.ParseExact(to, "dd.MM.yyyy", null);
        var client = new Timetables();
        var result = client.GetJourneys(startDate, endDate.AddDays(1), portFrom, portTo);
        var js = result
            .GroupBy(x => x.DepartureTime.CarResToDateTime())
            .Select(x => x.Key)
            .OfType<DateTime>()
            .Select(x => x.Date)
            .Distinct()
            .ToDictionary(x => x.Date.ToString("dd.MM.yyy"), x => true);
        return new AjaxDictionary<string, bool>(js);
    }

    #endregion

    #region Nested type: AjaxDictionary

    [Serializable]
    public class AjaxDictionary<TKey, TValue> : ISerializable
    {
        private readonly Dictionary<TKey, TValue> _dictionary;

        public AjaxDictionary()
        {
            _dictionary = new Dictionary<TKey, TValue>();
        }

        public AjaxDictionary(Dictionary<TKey, TValue> dic)
        {
            _dictionary = dic;
        }

        public AjaxDictionary(SerializationInfo info, StreamingContext context)
        {
            _dictionary = new Dictionary<TKey, TValue>();
        }

        public TValue this[TKey key]
        {
            get { return _dictionary[key]; }
            set { _dictionary[key] = value; }
        }

        #region ISerializable Members

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            foreach (var key in _dictionary.Keys)
                info.AddValue(key is string ? key as string : key.ToString(), _dictionary[key]);
        }

        #endregion

        public void Add(TKey key, TValue value)
        {
            _dictionary.Add(key, value);
        }
    }

    #endregion
}

Edit: adding a comment to the accepted answer:
This is true for javascript, but not as I can see for JSON. Looks like the serializer is a little fanatic in not only serializing to JSON, but also ensuring that the JSON is javascript. Adding the full JSON syntax as found on https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/JSON

JSON = null
    or true or false
    or JSONNumber
    or JSONString
    or JSONObject
    or JSONArray

JSONNumber = - PositiveNumber
          or PositiveNumber
PositiveNumber = DecimalNumber
              or DecimalNumber . Digits
              or DecimalNumber . Digits ExponentPart
              or DecimalNumber ExponentPart
DecimalNumber = 0
             or OneToNine Digits
ExponentPart = e Exponent
            or E Exponent
Exponent = Digits
        or + Digits
        or - Digits
Digits = Digit
      or Digits Digit
Digit = 0 through 9
OneToNine = 1 through 9

JSONString = ""
          or " StringCharacters "
StringCharacters = StringCharacter
                or StringCharacters StringCharacter
StringCharacter = any character
                  except " or \ or U+0000 through U+001F
               or EscapeSequence
EscapeSequence = \" or \/ or \\ or \b or \f or \n or \r or \t
              or \u HexDigit HexDigit HexDigit HexDigit
HexDigit = 0 through 9
        or A through F
        or a through f

JSONObject = { }
          or { Members }
Members = JSONString : JSON
       or Members , JSONString : JSON

JSONArray = [ ]
         or [ ArrayElements ]
ArrayElements = JSON
             or ArrayElements , JSON
  • 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-26T11:14:42+00:00Added an answer on May 26, 2026 at 11:14 am

    This is because in JSON (or JavaScript) the key name (or property in JavaScript) cannot start with a numeric value, hence it put those character after serializing them to make sure they are correct JSON format

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

Sidebar

Related Questions

I'm currently looking into using WCF to communicate between a server and a program
I am currently looking into spliting a very long string that could contain HTML
I'm currently looking into developing Facebook applications and was planning on using Flash as
I'm currently working on a project using C++ and DirectX9 and I'm looking into
I'm currently looking into using C++/CLI to bridge the gap between managed C# and
We are currently using StarTeam as our source control, but I am looking into
I am currently looking into an issue where an application is using alot of
I'm currently redesigning my website and have been looking into using JavaScript and jQuery.
I'm currently looking into XSS attacks, with the aim of using them in client
I'm currently looking into the RegisterClientScriptInclude method so I can be sure that I

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.