JSON

jquery-json 插件 - DIY技术区

字号+ 作者:H5之家 来源:H5之家 2015-09-16 08:06 我要评论( )

[b]示例:[/b] var thing = {plugin:

示例:

var thing = {plugin: 'jquery-json', version: 2.3};  
var encoded = $.toJSON( thing );
// '{"plugin":"jquery-json","version":2.3}'

var name = $.evalJSON( encoded ).plugin;
// "jquery-json"

var version = $.evalJSON(encoded).version;
// 2.3
=================================================

Most people asked me why I would want to do such a thing, which boggles my mind. JavaScript makes it relatively easy to convert from JSON, thanks to eval(), but converting to JSON is supposedly an edge requirement.

This plugin exposes four new functions onto the $, or jQuery object:

  • toJSON: Serializes a javascript object, number, string, or arry into JSON.
  • evalJSON: Converts from JSON to Javascript, quickly, and is trivial.
  • secureEvalJSON: Converts from JSON to Javascript, but does so while checking to see if the source is actually JSON, and not with other Javascript statements thrown in.
  • quoteString: Places quotes around a string, and inteligently escapes any quote, backslash, or control characters.

    google code :

    jquery.json-2.3.min.js (2.13 KB) 031

     

  • 1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

    相关文章
    • JSON and WebMatrix - building a JSON variable

      JSON and WebMatrix - building a JSON variable

      2016-01-18 16:07

    网友点评