jQuery data() object to JSON string
I'm trying convert jQuery Data object to JSON string.
I tried:
$.data(plant).toJSON()
JSON.stringify($.data(plant))
but doesn't seems to be working. It showing undefined in firebug.开发者_StackOverflow中文版(edited)
This is what I got when I log $.data(plant):
Object { residential="Condo", location="Garden", watering="Weekly"}
Can anyone tell me how to convert this jQuery data() object to JSON string?
Using JSON.stringify() should work just fine:
http://jsfiddle.net/petersendidit/gR4nQ/
精彩评论