views:

88

answers:

1

Is there a good example (code) for a datasource which binds to json data from a remote webservice?

Or is there another smart way to bind json formatted data against for instance a grid control? (either be it web or win forms)

I'm asking for the source code, since that way it can be tweaked a bit to the json better

A: 

This is an old, old question, but I figure I'll give it a go in case it's still looking for an answer. This isn't an automatic binding, and requires it to be manually changed any time the table's schema is, but it's what I've figured:

public ActionResult returnJSON(string filter)
    {
        DataTable table = FindDataWhere(filter);
        var data = new List<Dictionary<string, string>>();

        foreach (DataRow row in table.Rows)
        {
            var foo = new Dictionary<string, string>();
            location.Add("Col1", (string)row["Col1"]);
            location.Add("Col2", (string)row["Col2"]);
            location.Add("Col3", (string)row["Col3"]);
            data.Add(foo);
        }

        return Json(data);
    }
Zind