0
使用rails 2.3.8。JSON格式被错误地发布到/在rails中创建
我得到这样的:
[
[0] "0",
[1] {
"name" => "Section",
"contents" => {
"0" => {
"name" => "RENAMED!",
"id" => "1"
}
}
}
]
通知[0]和[1]
,但在我的岗位,我格式化了JSON是这样的:
[ {
"name":"Section",
"contents":[
{
"id":1,
"name":"RENAMED!"
}
]
}, .. more of this type of structure [
那么,为什么rails会添加额外的数组?
这里是如何我张贴的对象:
$j.ajax({
type: "POST",
url: 'http://url/objects/create/',
dataType: 'text',
async: false,
data: data_obj,
success: function() {
alert("sent");
}
});
UPDATE
data_obj = {
"my_object":{
"name":"hello there, I am JSON!",
"template_id":1,
"variables":{
"hello":"there",
"me":"you"
},
"sections":[
{
"name":"Section",
"contents":[
{
"id":1,
"name":"RENAMED!"
}
]
},
{
"name":"section2",
"contents":[
{
"name":"something",
"body":"nothing"
},
{
"id":2,
"name":"I renamed you",
"variables":{
"hello":"i'm amazing"
}
}
]
}
],
"attachments":[
{
"media_id":1
}
]
}
}
我会更新我的问题向您展示data_obj - 这一切都硬编码 – NullVoxPopuli 2012-02-27 19:18:30
更新的答案。 – 2012-02-27 22:40:31