Eval is evil… So what should I use instead?

前端 未结 9 1156
忘掉有多难
忘掉有多难 2020-11-27 17:27

An ajax request returns me a standard JSON array filled with my user\'s inputs. The input has been sanitized, and using the eval() function, I can easily create my javascrip

9条回答
  •  广开言路
    2020-11-27 18:01

    "stolen" from jQuery

    // Try to use the native JSON parser first
    return window.JSON && window.JSON.parse ?
        window.JSON.parse( data ) :
        (new Function("return " + data))();
    

提交回复
热议问题