我有这个 C# 对象:
var obj = new {
username = "andrey",
callback = "function(self) { return function() {self.doSomething()} (this) }"
}
我需要 JSON 序列化它以在 ajax 调用中传递给浏览器。我使用 JavascriptSerializer,但它序列化为以下 JSON:
{"username":"andrey", "callback": "function(self) { return function() {self.doSomething()} (this) }"}
但我需要的是:
{"username":"andrey", "callback": function(self) { return function() {self.doSomething()} (this) }}
- 函数定义周围没有引号。
现在,当 JSON 对象到达浏览器并被创建时,'callback' 参数不是一个函数,而是一个字符串。知道如何解决它,最好是在服务器端?