1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
[NonAction] public IActionResult SuccessResult(object data = null, string msg = "成功") { return ToJsonContent(new Result < object > () { Code = 200, Msg = msg, Data = data == null ? new {} : data }); }
[NonAction] public IActionResult ErrorResult(string msg, int code, HttpStatusCode statusCode = HttpStatusCode.OK) { return ToJsonContent(new Result < object > () { Code = code, Msg = msg, }); }
[NonAction] public IActionResult ToJsonContent(object obj, bool isNull = false) { JsonSerializerOptions options = new JsonSerializerOptions() { WriteIndented = true, AllowTrailingCommas = true, IgnoreNullValues = isNull, IgnoreReadOnlyProperties = true, PropertyNameCaseInsensitive = true, Encoder = JavaScriptEncoder.Create(UnicodeRanges.All), DictionaryKeyPolicy = JsonNamingPolicy.CamelCase }; options.Converters.Add(new DateTimeJsonConverter()); return Content(JsonSerializer.Serialize(obj, options)); }
|