Is it valid to define functions in JSON results?

后端 未结 11 876
一向
一向 2020-11-22 11:38

Part of a website\'s JSON response had this (... added for context):

{..., now:function(){return(new Date).getTime()}, ...}

Is adding anony

11条回答
  •  耶瑟儿~
    2020-11-22 12:09

    No.

    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.

    Per http://en.wikipedia.org/wiki/JSON, the "basic types" supported are:

    • 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

提交回复
热议问题