Is it valid to define functions in JSON results?

后端 未结 11 885
一向
一向 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:18

    Nope, definitely not.

    If you use a decent JSON serializer, it won't let you serialize a function like that. It's a valid OBJECT, but not valid JSON. Whatever that website's intent, it's not sending valid JSON.

提交回复
热议问题