亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

asp.net core 的webapi返回的屬性對名字是小名?

asp.net core 的webapi返回的屬性對名字是小名?

狐的傳說 2018-09-06 18:25:59
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.問題來了,我偏要保持大小寫怎么辦?
查看完整描述

2 回答

?
慕容708150

TA貢獻1831條經驗 獲得超4個贊

你主動把它序列化成字符串唄。

using Newtonsoft.Json;


namespace xxx{

public class JsonResult<T>

    {

       public JsonResult()

        {

           Value = default(T);

        }

        [JsonProperty("Status")]

        public string Status { set; get; }

        [JsonProperty("Value")]

        public T Value { set; get; } 

    }

}


查看完整回答
反對 回復 2018-09-23
?
智慧大石

TA貢獻1946條經驗 獲得超3個贊

core里很多json序列化的地方都比改成駝峰明明了.包括signalr.
解決辦法是修改全局json序列化配置
比如

        services.AddMvc().AddJsonOptions(options => options.SerializerSettings.ContractResolver = new DefaultContractResolver());


查看完整回答
反對 回復 2018-09-23
  • 2 回答
  • 0 關注
  • 650 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號