开发者

json2 stringify

开发者 https://www.devze.com 2023-03-29 15:22 出处:网络
I have seen several posts about json2.js and the stringify method it provides.However, the posts I have seen are from almost a year ago.Is there a better library to use today or does jQuery direct开发

I have seen several posts about json2.js and the stringify method it provides. However, the posts I have seen are from almost a year ago. Is there a better library to use today or does jQuery direct开发者_如何学运维ly support stringify functionality?


The JSON object has been defined in ECMAScript 5th ed, and is already available in most modern browsers. No special setup is needed. Calling,

JSON.stringify(someObject)

will spit out a JSON representation of the passed in object. If you want compatibility for older browsers, then simply include Crocford's json2.js on your page. json2.js will use the browser's native implementation, if available.


You can use the .serialize() method on a form to give you a JSON string of a jQuery form object. It's usually what I use if I'm doing an AJAX POST request.

Example:

<form id="SomeForm">
    <input name="hello" type="hidden" value="world" />
</form>

<script>
    $('#SomeForm').serialize(); // '{ "hello": "world" }'
</script>
0

精彩评论

暂无评论...
验证码 换一张
取 消