你如何与序列化使用JSON方法的JavaScript对象 [英] How do you serialize javascript objects with methods using JSON

查看:127
本文介绍了你如何与序列化使用JSON方法的JavaScript对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要寻找的增强,JSON,也将序列化的方法。我有作为对象的集合对象,想序列化的集合对象的方法为好。到目前为止,我已经位于 ClassyJSON 。有什么想法?

I am looking for an enhancement to JSON that will also serialize methods. I have an object that acts as a collection of objects, and would like to serialize the methods of the collection object as well. So far I've located ClassyJSON. Any thoughts?

推荐答案

我不认为序列化方法是有史以来一个好主意。如果您打算运行code服务器端,打开自己的攻击。如果你想运行客户端,你是关闭只是本地方法更好,可能引用您打算在序列化对象使用的方法的名称。

I don't think serializing methods is ever a good idea. If you intend to run the code serverside, you open yourself to attacks. If you want to run it client side, you are better off just the local methods, possibly referencing the name of the method you are going to use in the serialized objects.

我相信虽然这F =+功能(){}将产生你一个字符串版本,您可以EVAL:
VAR测试=F =+功能(){警报(你好);};

I do believe though that "f = "+function() {} will yield you a to string version that you can eval: var test = "f = "+function() {alert("Hello");};

的eval(测试)

和良好的JSON处理,我会建议样机,这对对象序列化到JSON伟大的方法。

And for good json handling, I would recommend prototype, which has great methods for serializing objects to json.

这篇关于你如何与序列化使用JSON方法的JavaScript对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆