将返回的结果写入JSON

时间:2013-08-06 12:14:03

标签: c# asp.net-mvc json

不确定从哪里开始,我想写回到json的结果

当前代码:

   public Setting TestSettings(Example _example, String type)
    {
        var results = _example.GetExample("Testing");
        return results;
    }

设置模型

string Description { get; set; }
Guid? Guid1 { get; set; }
Guid? Guid2 { get; set; }
string Key { get; set; }
string Value { get; set; }

GetExample

public Setting GetExample(string key)
        {
            using (var db = MyDataContext.StoredProcs)
            {
                return db.GetExample<Setting>(key, _curGuid1, _curGuid2, SettingExtensions.SettingFactory());
            }
    }

1 个答案:

答案 0 :(得分:0)

你可以试试这个

 var resultslist = _example.GetExample("Testing");

 var result = new DataSourceResult()
 {
    Data = resultslist 
 };
 return Json(result, JsonRequestBehavior.AllowGet);