家里总停电

.NET MVC json对象或者json对象数组的序列化和反序列化(一)

电脑版发表于:2019/10/16 9:49

1、用JSON.stringify()将对象stuarr或者json数组stuarr序列化成字符串,然后提交给后台。

 $.post("/home/DoUpdate", {stus:JSON.stringify(stuarr)}, function (result) {
                
            })


2、给下面action定义一个参数字符串接受前台提交的字符串,再导入命名空间using Newtonsoft.Json,然后通过JsonConvert.DeserializeObject把字符串反序列化成对象或者对象集合。

public ActionResult DoUpdate(string stus)
        {
            List<stuinfo> list = JsonConvert.DeserializeObject<List<stuinfo>>(stus);
            
            return View();

        }

关于TNBLOG
TNBLOG,技术分享。技术交流:群号677373950
ICP备案 :渝ICP备18016597号-1
App store Android
精彩评论
{{item.replyName}}
{{item.content}}
{{item.time}}
{{subpj.replyName}}
@{{subpj.beReplyName}}{{subpj.content}}
{{subpj.time}}
猜你喜欢