Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Although I agree that JavaScriptSerializer is a crap and Json.Net is a better option, there is a way in which you can make JavaScriptSerializer serialize the way you want to. You will have to register a converter and override the Serialize method using something like this:</p> <pre><code> public class KeyValuePairJsonConverter : JavaScriptConverter { public override object Deserialize(IDictionary&lt;string, object&gt; dictionary, Type type, JavaScriptSerializer serializer) { var instance = Activator.CreateInstance(type); foreach (var p in instance.GetType().GetPublicProperties()) { instance.GetType().GetProperty(p.Name).SetValue(instance, dictionary[p.Name], null); dictionary.Remove(p.Name); } foreach (var item in dictionary) (instance).Add(item.Key, item.Value); return instance; } public override IDictionary&lt;string, object&gt; Serialize(object obj, JavaScriptSerializer serializer) { var result = new Dictionary&lt;string, object&gt;(); var dictionary = obj as IDictionary&lt;string, object&gt;; foreach (var item in dictionary) result.Add(item.Key, item.Value); return result; } public override IEnumerable&lt;Type&gt; SupportedTypes { get { return new ReadOnlyCollection&lt;Type&gt;(new Type[] { typeof(your_type) }); } } } JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer(); javaScriptSerializer.RegisterConverters(new JavaScriptConverter[] { new ExpandoJsonConverter() }); jsonOfTest = javaScriptSerializer.Serialize(test); // {"x":"xvalue","y":"\/Date(1314108923000)\/"} </code></pre> <p>Hope this helps!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload