常见问题汇总

1. c# web项目使用集合形式的参数,接收不到参数出现如下错误时 "The JSON request was too large to be deserialized"。解决方案如下:

        [HttpPost]
        public async Task<JsonResult> ReceivemThirdPartyMatPrice()
        {
            // 获取请求体的原始 JSON 数据
            string rawJson = await new System.IO.StreamReader(Request.InputStream).ReadToEndAsync();
            // 使用 Newtonsoft.Json 来反序列化,并指定配置
            var jsonSettings = new JsonSerializerSettings
            {
                MaxDepth = 3,  // 可以增加最大深度
                NullValueHandling = NullValueHandling.Ignore,  // 忽略空值
                DefaultValueHandling = DefaultValueHandling.Ignore,
                Formatting = Formatting.Indented
            };
            // 反序列化 JSON 数据
            var list = JsonConvert.DeserializeObject<List<ThirdPartyMatPrice>>(rawJson, jsonSettings);
            //开始处理接收的list列表数据
        }

  

 

posted @ 2024-12-19 16:18  ssnice  阅读(29)  评论(0)    收藏  举报