在JSON结果中定义函数是否有效? [英] Is it valid to define functions in JSON results?
本文介绍了在JSON结果中定义函数是否有效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
网站的JSON响应的一部分对此具有...(为上下文添加...)
Part of a website's JSON response had this (... added for context):
{..., now:function(){return(new Date).getTime()}, ...}
向JSON添加匿名函数是否有效?我希望每次您访问时间"都会返回不同的值.
Is adding anonymous functions to JSON valid? I would expect each time you access 'time' to return a different value.
推荐答案
否.
JSON纯粹是一种数据描述语言.如 http://www.json.org 所述,它是轻量级数据交换格式". -不是编程语言.
JSON is purely meant to be a data description language. As noted on http://www.json.org, it is a "lightweight data-interchange format." - not a programming language.
根据 http://en.wikipedia.org/wiki/JSON ,基本支持的类型:
Per http://en.wikipedia.org/wiki/JSON, the "basic types" supported are:
- 数字(整数,实数或浮点数 点)
- 字符串(双引号Unicode 带有反斜线转义)
- 布尔值 (对与错)
- 数组(有序 值序列,以逗号分隔 并放在方括号中)
- 对象(键:值的集合 对,以逗号分隔并包含在内 花括号中的)
-
null
- Number (integer, real, or floating point)
- String (double-quoted Unicode with backslash escaping)
- Boolean (true and false)
- Array (an ordered sequence of values, comma-separated and enclosed in square brackets)
- Object (collection of key:value pairs, comma-separated and enclosed in curly braces)
null
这篇关于在JSON结果中定义函数是否有效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文