设为首页收藏本站
开启辅助访问
切换到宽版

创星网络[分享知识 传递快乐]

 找回密码
 立即注册

QQ登录

只需一步,快速开始

用新浪微博登录

只需一步,快速搞定

搜索
查看: 4522|回复: 0
打印 上一主题 下一主题

[JQuery] jquery-json

[复制链接]

我玩的应用:

跳转到指定楼层
楼主
发表于 2012-12-13 23:01:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Important: 2.0 is not backwards compatible with the previous versions.  Changes in version 2.0 are described below.
This plugin makes it simple to convert to and from JSON:
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.3Most 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 array 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 intelligently escapes any quote, backslash, or control characters.
Changes in Version 2.3
  • Direct reference established to the native browser API if available. If the native browser API is available $.toJSON, $.evalJSON and $.secureEvalJSON link directly to the native JSON.stringify and JSON.parse, no longer checks on every call (issue 49)
  • Several minor performance improvements (issue 48)
  • Several bug fixes (such as issue 27)
  • Reorganized testing environment (now using QUnit)
  • Code clean up and JSHint validation (Yay!)
Changes in Version 2.0
  • The code has been re-written.  It is now easier to read and follow; less of a mish-mash.
  • Support for native JSON has been included.  This means that if you are using a browser that supports JSON.stringify, it will be used.  Also evalJSON and secureEvalJSON will use JSON.parse if available.
  • Changes were made in the JSON output to move in line with the JSON object standard.  This means 2.0is not backwards compatible with the previous versions.
  • toJSON now renders like compactJSON used to and compactJSON does not exist anymore.  As per the JSON object standard, needless spaces are now removed.  This makes it less readable; if someone wants to send me a prettyJSON patch, it will be welcome.
  • Differences between output when JSON.stringify is available and when it is not could exist.  I am unable to test all strings.  Be aware when testing your apps.

from:http://go.cxweb.com.cn/95bvq
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 转播转播 分享分享 分享淘帖
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|创星网络 ( 苏ICP备11027519号|网站地图  

GMT+8, 2024-9-22 07:09 , Processed in 0.078595 second(s), 22 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表