将嵌套的json解析为ajax

时间:2017-04-14 13:30:28

标签: jquery ajax

我的样本json结构为,

{ key : { "data1":data1, "data2":data2 }}

我希望将其解析为'数据'

$.ajax({
    type: 'post',
    url: 'url',
    data: <--- here ,
    success: function() { 
        *****
    }
});

我该怎么做?

1 个答案:

答案 0 :(得分:1)

尝试使用JSON.stringify

var data= { "key" : {"data1":"data1", "data2":"data2" }};
new Request.JSON({
    url: '/echo/json/',
    type: "POST",
    data: JSON.stringify(data),
    contentType: "application/json",
    onSuccess: function(res) {
        document.write(data.key.data1);
        console.log(data.key.data1);
    }
}).send();

这是工作的jsfiddle:http://jsfiddle.net/dK5DL/87/