webapi [FromBody] 接收数据不对

ajax:


        var json = {
            UserName: "chog test",
            UserPassword: "chog123321",
            UserPhone: "110",
            Address: {
                Province:"省",
                City:"城市",
                County:"国家",
                AddressDetails:"详细地址",
            },
            IsDeleted: true,
            IsDisable: true,
            CreateUserId: "e7bf9773-8231-44af-8d53-e624f0433940",
            CreateUserName: "admin"
        }
        var data = JSON.stringify(json);

        $.ajax({
            type: 'POST',
            url: 'https://localhost:5001/api/User/AddUserInfoM',
            // url: 'https://localhost:5001/api/values/Test',
            // dataType: 'json',
            contentType: 'application/json',
            data: data,
            // data:JSON.stringify({a:'1',b:'2'}),
            error: function (XMLHttpRequest) {
                alert('post error!');
            },
            success: function (data) {
                alert(data.message);
            }
        });

接收到的数据
图片说明

上图为什么接收到的数据,外面是两个括号呢?

去掉var data = JSON.stringify(json);
“data: data, ”改成 “data: json,”
var json = { UserName: "chog test", UserPassword: "chog123321", UserPhone: "110", Address: { Province:"省", City:"城市", County:"国家", AddressDetails:"详细地址", }, IsDeleted: true, IsDisable: true, CreateUserId: "e7bf9773-8231-44af-8d53-e624f0433940", CreateUserName: "admin" }
改成
var json = ' UserName: "chog test", UserPassword: "chog123321", UserPhone: "110", Address: { Province:"省", City:"城市", County:"国家", AddressDetails:"详细地址", }, IsDeleted: true, IsDisable: true, CreateUserId: "e7bf9773-8231-44af-8d53-e624f0433940", CreateUserName: "admin" ' 

一般情况下,JASON.stringfy(inputstack) 用于 ajax前台送后台数据,后台返前台用data:jason解,如果不好用,可以直接在success中输出数据格式:resp.data[i].needfield ,可以自己试试。主要是格式转换。

http://www.cnblogs.com/siazon/p/6083660.html

你定义的 本来就是json,就不需要 stringify 了,你可以去 就可以了