我的样本json结构为,
{ key : { "data1":data1, "data2":data2 }}
我希望将其解析为'数据'
$.ajax({
type: 'post',
url: 'url',
data: <--- here ,
success: function() {
*****
}
});
我该怎么做?
答案 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/