漫谈JQUERY和JSON冲突进行学习研究

开发 开发工具
下面着重介绍JQUERY和JSON冲突来进行学习,是件很头疼的事情 ,和项目经理商量了一下,提议在原框架的基础上引入JQUERY,版本是最新版1.3.。

本文介绍JQUERY和JSON冲突的使用问题介绍说明(使用Ruby on rails框架进行讲解,因为它所有的配置文件都是使用的YAML)以及它与XML和JSON的区别,***讨论了YAML的优势和缺点。

引入之后,发现某些方法用不了,报错,怪异,逐步的排查,折腾了一下午,终于发现公司的框架里引入了json.js,看了json.js的源码,删掉之后,功能正常,网上搜搜这些,发现遇到这种问题的人不在少数,解决方法大致如下:#T#
1.有说调整js加载先后顺序的
2.还有直接使用Jquery的专用JSON.js

但是这两种方案不适于我,因为是公司框架封装起来的东西,不能改动。我用的是下面的方法变通的解决办法就是仿照下面的解决方法做的:在js代码里加上这么一句
delete(Object.prototype.toJSONString);,问题解决。我测试成功,暂时没有发现问题。PS:没见过这种在页面直接就能调用delete(Object.prototype)的方法,有时间还是要好好研究一下js面向对象的东西。

  1. Martin Cooper  
  2. // after json.js has loaded...  
  3. > // define a namespace to minimize footprint  
  4. > var JSON = {};  
  5. > 
  6. > // add all of the methods  
  7. > JSON.arrayToJSONString = Array.prototype.toJSONString;  
  8. > JSON.booleanToJSONString = Boolean.prototype.toJSONString;  
  9. > JSON.dateToJSONString = Date.prototype.toJSONString;  
  10. > JSON.numberToJSONString = Number.prototype.toJSONString;  
  11. > JSON.objectToJSONString = Object.prototype.toJSONString;  
  12. > JSON.stringToJSONString = String.prototype.toJSONString;  
  13. > JSON.parseJSON = String.prototype.parseJSON;  
  14. > 
  15. > // remove all the methods from intrinsic objects  
  16. > delete(Array.prototype.toJSONString);  
  17. > delete(Boolean.prototype.toJSONString);  
  18. > delete(Date.prototype.toJSONString);  
  19. > delete(Number.prototype.toJSONString);  
  20. > delete(Object.prototype.toJSONString);  
  21. > delete(String.prototype.toJSONString);  
  22. > delete(String.prototype.parseJSON); 
责任编辑:chenqingxiang 来源: pcdog
相关推荐

2010-01-08 15:30:15

JSON格式举例

2010-01-05 17:59:46

PHP JSON数组对

2010-01-12 10:50:59

学习C++

2010-03-02 15:10:27

Android系统

2010-01-05 13:47:43

Jquery Json

2010-01-04 17:20:47

ADO属性

2009-12-28 11:14:53

ADO 连接对象

2010-01-06 18:29:46

安装JSON插件

2010-03-01 15:57:59

Python开发工具

2010-02-02 15:48:49

Python数据库

2010-03-10 18:29:57

2010-03-01 14:02:26

Python批处理语言

2010-03-01 15:23:24

Python操作语言

2010-02-26 15:43:02

Python线程

2010-01-06 10:18:02

JSON类

2010-01-07 13:11:09

设置JSON

2010-01-12 14:22:26

Visual C++

2009-12-23 16:21:38

ADO.NET工具

2010-02-23 16:06:58

Python 命令行

2010-01-04 10:14:04

ADO.NET对象模型
点赞
收藏

51CTO技术栈公众号