JSON序列化和反序列化 對decmail 取值問題

地圖API返回經緯度:經度: 緯度:json

lng":114.03483089395202,"lat":22.615589046911805框架

decmail 接收數據後兩位會截掉  系統框架默認取得是double類型 oop

解決方式是 進行設置  json.FloatParseHandling = FloatParseHandling.Decimal;    setting.FloatParseHandling = FloatParseHandling.Decimal;  便可spa

 /// <summary> 
        /// JSON對象反序列化 /// </summary> 
        /// <param name="JSON"></param>  
        /// <returns></returns> 
        public static T DeserializeObject<T>(string JSON) { 
            Newtonsoft.Json.JsonSerializer json = new Newtonsoft.Json.JsonSerializer(); json.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore; json.ObjectCreationHandling = Newtonsoft.Json.ObjectCreationHandling.Replace; json.MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Ignore; json.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; json.FloatParseHandling = FloatParseHandling.Decimal; json.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat; json.DateFormatString = "yyyy-MM-dd HH:mm:ss"; StringReader sr = new StringReader(JSON); Newtonsoft.Json.JsonTextReader reader = new JsonTextReader(sr); T result = (T)json.Deserialize(reader, typeof(T)); reader.Close(); return result; }
        /// <summary>
        /// 序列化爲JSON
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static string SerializeObject(object value, bool NullValueIgnore = true)
        {
            JsonSerializerSettings setting = new JsonSerializerSettings();
            
            setting.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.MicrosoftDateFormat;
            setting.FloatParseHandling = FloatParseHandling.Decimal;
            setting.DateFormatString = "yyyy-MM-dd HH:mm:ss";
            setting.Converters.Add(EnumConverter);
            //空值處理
            if (NullValueIgnore)
                setting.NullValueHandling = NullValueHandling.Ignore;
 
 
            //包含實體默認值
            setting.DefaultValueHandling = DefaultValueHandling.Include;
            return JsonConvert.SerializeObject(value, Formatting.Indented, setting);
           
 
 
        }
 

 

相關文章
相關標籤/搜索