我想知道这些选项中哪个是最好的,以便使用 C# 返回一个 json 对象:
选项1:
public EmptyResult GetImages() {
/*operations*/
ControllerContext.HttpContext.Response.AddHeader("content-type", "application/json");
ControllerContext.HttpContext.Response.Write(JsonConvert.SerializeObject(images));
return new EmptyResult();
}
或选项 2:
public EmptyResult GetImages() {
/*operations*/
return Json(images);
}