如何获取和显示rails创建的json对象?

时间:2011-10-14 07:56:52

标签: jquery ruby-on-rails json

我已经看到了将数组转换为json但不是纯变量的示例。我是json的新手,需要一个可以打印出类似内容的ajax / javascript函数:

{"name":["1"],"email":["1"],"phone":["1"],"subject":["1"],"message":["1"]}

1 个答案:

答案 0 :(得分:0)

我创建了一个jsfiddle.net,向您展示如何执行此操作:

http://jsfiddle.net/6kLfk/

javascript是这样的:

var data = {
"name": ["1"],
"email": ["1"],
"phone": ["1"],
"subject": ["1"],
"message": ["1"]
}

$.each(data, function(key, value) {
    $('#test').append(key + ": " + value + "<br />");
});

输出:

name: 1
email: 1
phone: 1
subject: 1
message: 1