日期:2014-05-16  浏览次数:20327 次

json使用

?

?JavaScript?中使用?JSON

掌握了?JSON?格式之后,在?JavaScript?中使用它就很简单了。JSON??JavaScript?原生格式,这意味着在?JavaScript?中处理?JSON?数据不需要任何特殊的?API?或工具包。

?JSON?数据赋值给变量

例如,可以创建一个新的?JavaScript?变量,然后将?JSON?格式的数据字符串直接赋值给它:

var people =
?{ "programmers": [
??? { "firstName": "Brett", "lastName":"McLaughlin", "email": "brett@newInstance.com" },
??? { "firstName": "Jason", "lastName":"Hunter", "email": "jason@servlets.com" },
??? { "firstName": "Elliotte", "lastName":"Harold", "email": "elharo@macfaq.com" }
?? ],
?"authors": [
??? { "firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction" },
??? { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" },
??? { "firstName": "Frank", "lastName": "Peretti",