Json.Net And ActionResult

前端 未结 2 532
醉话见心
醉话见心 2020-12-09 03:14

Im building a JObject myself and want to return it as ActionResult. I dont want to create and then serialize a data object

For example

public ActionR         


        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-09 03:51

    In case, if you take care of JSON Formatting , just return JSON Formatted string

    public string Test(string id)
    {
          var res = new JObject();
          JArray array = new JArray();
          array.Add("Manual text");
          array.Add(new DateTime(2000, 5, 23));
          res["id"] = 1;
          res["result"] = array;
          return YourJSONSerializedString;
    }
    

    else Use built in JsonResult(ActionResult)

        public JsonResult Test(string id)
        {
    
              return Json(objectToConvert);
        }
    

提交回复
热议问题