If I have a JSON array that I’m reciving from the server and I want to use it (for example) for autocomplete — I can just make a JavaScript array, and use a loop to place the JSON values into the array and then use it for my autocomplete.
Is that way really wrong?
Thanks !
The response you receive from the server will be a string, which is not very useful for making a loop.
I assume that you wish to use a split or regex to parse the JSON yourself.
That is fine, and is actually safer than eval’ing the incoming data – and quicker than most standard regexs for the task.
However, it loses the advantages of having the incoming data in a format understood by JS, and you are likely to miss something that might theoretically be exploited.
In Firefox 3.1, JSON parsing is native and safe. Once that becomes standard, there would be no benefit to using your own parser. Till then, its a question of tradeoff – how much work would you need to invest for what risk and benefit.