jQuery序列化对象?
问题描述:
说我有类似的东西:
var obj = {id: 1, name: "Some name", color: "#444444" };
我要序列化该对象.我试过了:
I want to serialize that object. I tried:
$(obj).serialize();
但这没用.
有什么想法吗?
答
您应改为使用 jQuery.param()
.
You should use jQuery.param()
instead.
使用香草JS时,您将改为使用 JSON.stringify
.
With vanilla JS, you would use JSON.stringify
instead.