This project has moved and is read-only. For the latest updates, please go here.

Json format keyvalues only

Apr 23, 2013 at 9:43 PM
Hello How to get the following format using JSON.NET?

"123": "CustomerA",

Currently when I Serialize my object I get the data in the following format
Name: "CustomerA",
ID: "123"
Name: "CustomerB",
ID: "345"
etc etc
Jun 5, 2013 at 3:53 PM
Edited Jun 5, 2013 at 4:03 PM
I am sure there is a reason not to do this... but I use a helper (.ashx) file like this
public void ProcessRequest(HttpContext context)
    context.Response.ContentType = "application/json";
    Dictionary<String, String> dictionary = new Dictionary<String, String>();

    dictionary.Add("123", "CustomerA");
    dictionary.Add("345", "CustomerB");
    dictionary.Add("789", "CustomerC");

Then the client does something like
        success: (function (result) {
            for (var key in result)
                alert(key + ' ' + result[key]);