• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C#Newtonsoft.Json.JsonReaderException:“Couldnotconvertstringtodecimal:

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

使用Newtonsoft.Json,报以上错误,问题的原因是有"",把“”替换成null:

以前的json:

[{"WengvNj":"df5c38c6dd1744c59605da1fc85a0500","WengvSgtm":"2019-12-16 修理合同","WengvSu":"2019TJR001LX","WengvYewm":"修理","WengvXzhbdc":"1","WengvSuam":"","WengvXonvmkeq":"2019/12/16 0:00:00","WengvKosqjvp":"GK","WengvHapl":"SVH30","WengvWgaqoijz":"Y","WengvWgaqoiyags":"OK,同意!","WengvWgaqoixma":"wecrew","WengvWgaqoiomgs":"2019/12/16 10:20:10","WengvUrhvmkeqfhphk":"2019/12/16 0:00:00","WengvFyrbjuppnht":"2020/2/13 0:00:00","WengvWkhtrdjpnhtikskn":"2019/12/16 0:00:00","WengvWkhtrdjfnyttrlx":"","WengvJslz":"0","WengvYxhvbzzdg":"1","WengvUgfunxeoba":"","WengvUgfunxeyrh":"0","WengvUgfunxeegoikj":"","WengvJdjpjxrq":"","WengvHayznxnk":"CNY","WengvUgfunxeeha":"","WengvXat":"4400","WengvFmlvli":"LMF","WengvYxhlndjbr":"EXW","WengvXvlkrkwzbht":"","WengvHxlicoxma":"wecrew","WengvHxlicoomgs":"2019/12/16 10:19:46","WengvQgzbmkeq":"","WengvAgsqm":"","WengvTxkmanlfr":"","WengvFoyuxnp":"","WengvGafma":"","WengvGafmazsaas":"","WengvGafmaoxmvz":"","WengvAkulxb":"","WengvAkulxbtzicxsvswx":"","WengvAkulxbdtvdptu":"","WengvAkulxblpq":"","WengvAkulxbwuaybqe":"","WengvAkulxbwuayexffx":"","WengvAkulxbwuaytcrae":"","WengvGafmavtzxapd":"","WengvGafmavtzxdweew":"","WengvGafmavtzxsbqzd":"","WengvGafmamzzswgc":"","WengvGafmakabeckui":"","WengvGafmamzzswgcusmy":"","WengvAkulxbnaatxhd":"","WengvAkulxbdutbieiq":"","WengvAkulxbnaatxhdvtnz":"","WengvHuubaknfgmeu":"","WengvXkulyoamvfptu":"","WengvXkulyoamvfayec":"","WengvXkulyoamvfayecibjjb":"","WengvWkwirbxmaost":"","WengvWkwirbxmazxdb":"","WengvWkwirbxmazxdbhaiia":"","WengvXkulyoamvfhyxfmimu":"","WengvXkulyoamvfhyxfmimuayse":"","WengvWkwirbdutbieiq":"","WengvWkwirbdutbieiqwuoa":""}]

  解决方案:

        public string RemoveJsonFieldIsNull(string str)
        {
            if (string.IsNullOrEmpty(str)) return str;
            string reg=":\"\"";
            str = ReplaceByRegex(reg, str, ":null");

            return str;

            //string reg = "(?<beginStr>[^\"]*?)(?<key>\"?We*?\"?:?)(?<value>\".*?\",*)(?<endStr>[^\"]*?)";
            //string strSrcReg = "(?<beginSrc>^.*?(?=images))(?<char>(images))(?<endSrc>(?<=images).*?$)";
           // string reg = "(?<beginStr>^.*?)(?=:\"\")(?<value>(:\"\"))(?<endStr>(?<=:\"\").*?$)";
            //string reg = "(?<beginStr>^.*?)(?<value>(:\"\"))(?<endStr>.*?$)";
            //return ReplaceByRegex(reg, str, match =>
            //{
            //    string beginStr = match.Groups["beginStr"].Value;
            //    string value = match.Groups["value"].Value;
            //    string endStr = match.Groups["endStr"].Value;
            //    return beginStr+ ":null"+ endStr;
            //});
        }
        public static string ReplaceByRegex(string strReg, string html, string target)
        {
            return ReplaceByRegex(strReg, html, m => target);
        }
        public static string ReplaceByRegex(string strReg, string html, MatchEvaluator function)
        {
            if (string.IsNullOrEmpty(html) || string.IsNullOrEmpty(strReg)) return null;

            Regex regex = new Regex(strReg, RegexOptions.Singleline | RegexOptions.IgnoreCase);

            html = regex.Replace(html, function);
            return html;
        }

  

//去掉为json中value为null的key
            var jsonSetting = new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore };

  处理后的json:

[{"WengvNj":"df5c38c6dd1744c59605da1fc85a0500","WengvSgtm":"2019-12-16 修理合同","WengvSu":"2019TJR001LX","WengvYewm":"修理","WengvXzhbdc":"1","WengvSuam":null,"WengvXonvmkeq":"2019/12/16 0:00:00","WengvKosqjvp":"GK","WengvHapl":"SVH30","WengvWgaqoijz":"Y","WengvWgaqoiyags":"OK,同意!","WengvWgaqoixma":"wecrew","WengvWgaqoiomgs":"2019/12/16 10:20:10","WengvUrhvmkeqfhphk":"2019/12/16 0:00:00","WengvFyrbjuppnht":"2020/2/13 0:00:00","WengvWkhtrdjpnhtikskn":"2019/12/16 0:00:00","WengvWkhtrdjfnyttrlx":null,"WengvJslz":"0","WengvYxhvbzzdg":"1","WengvUgfunxeoba":null,"WengvUgfunxeyrh":"0","WengvUgfunxeegoikj":null,"WengvJdjpjxrq":null,"WengvHayznxnk":"CNY","WengvUgfunxeeha":null,"WengvXat":"4400","WengvFmlvli":"LMF","WengvYxhlndjbr":"EXW","WengvXvlkrkwzbht":null,"WengvHxlicoxma":"wecrew","WengvHxlicoomgs":"2019/12/16 10:19:46","WengvQgzbmkeq":null,"WengvAgsqm":null,"WengvTxkmanlfr":null,"WengvFoyuxnp":null,"WengvGafma":null,"WengvGafmazsaas":null,"WengvGafmaoxmvz":null,"WengvAkulxb":null,"WengvAkulxbtzicxsvswx":null,"WengvAkulxbdtvdptu":null,"WengvAkulxblpq":null,"WengvAkulxbwuaybqe":null,"WengvAkulxbwuayexffx":null,"WengvAkulxbwuaytcrae":null,"WengvGafmavtzxapd":null,"WengvGafmavtzxdweew":null,"WengvGafmavtzxsbqzd":null,"WengvGafmamzzswgc":null,"WengvGafmakabeckui":null,"WengvGafmamzzswgcusmy":null,"WengvAkulxbnaatxhd":null,"WengvAkulxbdutbieiq":null,"WengvAkulxbnaatxhdvtnz":null,"WengvHuubaknfgmeu":null,"WengvXkulyoamvfptu":null,"WengvXkulyoamvfayec":null,"WengvXkulyoamvfayecibjjb":null,"WengvWkwirbxmaost":null,"WengvWkwirbxmazxdb":null,"WengvWkwirbxmazxdbhaiia":null,"WengvXkulyoamvfhyxfmimu":null,"WengvXkulyoamvfhyxfmimuayse":null,"WengvWkwirbdutbieiq":null,"WengvWkwirbdutbieiqwuoa":null}]

  

 


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap