任何人都可以帮助我如何从 Rails 解码 JSON 对象。基本上我有 javascript 函数来编码 JSON 对象并将其传递给 Rails。
function save(){
----
----
notesArray.push({ Index: i, Title: title.val(), Content: content.val()});
// json encode it
var jsonStr = JSON.stringify(notesArray);
//sending to rails
$.post('monkey', {notes: jsonStr});
}
我不知道如何在 Rails 的 Controller 中对其进行解码。我还希望它将它保存在我的数据库(SQLite)中。知道如何做到这一点吗?
最佳答案
obj = ActiveSupport::JSON.decode(json_string)
但是它很慢,请查看这个以获取更快的扩展:http://flori.github.com/json/
关于ruby-on-rails - 如何在 Rails 中解码 JSON 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8461915/