As far as I know it is considered bad practice to eval()
JSON objects in JavaScript, because of security. I can understand this concern if the JSON comes from another server.
But if the JSON is provided by my own server and is created using PHP's json_encode
(let us assume it is not buggy), is it legitimate to simply use eval()
to read the JSON in JS or are there any security problem I currently can't think of?
I really don't want to deal with dynamically loading a JSON parser and would be glad to simply use eval()
.
PS: I will obviously use the native JSON
object if it is available, but want to fall back to eval()
for IE/Opera.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…