public class JsonResult<T>
{ public JsonResult() { Value = default(T); } public string Status { set; get; } public T Value { set; get; } } public async Task<JsonResult<string>> LoginApi(User userFromFore) 搞了我老半天发现原来返回的json是 status而不时Status.问题来了,我偏要保持大小写怎么办?
欧阳克2016-11-12 10:05:07
你主动把它序列化成字符串呗。
using Newtonsoft.Json; namespace xxx{ public class JsonResult{ public JsonResult() { Value = default(T); } [JsonProperty("Status")] public string Status { set; get; } [JsonProperty("Value")] public T Value { set; get; } } }
三叔2016-11-12 10:04:48
core里很多json序列化的地方都比改成驼峰明明了.包括signalr.
解决办法是修改全局json序列化配置
比如
services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());