如何将JSON数据存储为JavaScript表格式?

问题描述:

我正在开发一个Web应用程序,并且将jQuery 1.5和JavaScript用于该应用程序的主要功能.我从我的应用程序连接到RESTful界面,从中我可以获取一个人的信息. 我使用此函数从json页面检索信息:

I am developing a web application and I use jQuery 1.5 and JavaScript for the main functionality of the app. I connect from my app to a RESTful interface where I GET information for a person. I use this function to retrieve the information from the json page:

var jqxhr = $.getJSON("example.json", function() { // store the data in a table }

我的json格式的数据类似,但结果将导致不止一个人具有以下格式:

My data in json format are like but I will get as a result more than one persons having the format of:

[{"person":{"time":"2010-02-18T17:59:44","id":1,"name": "John","age":60, "updated_at":"010-02-18T17:59:44"}}]

我如何仅将ID,姓名和年龄存储在JavaScript表(更精确地说是数组)中,而忽略其余信息?

How can I store only the id, the name and the age of the person in a JavaScript table (to be more precise an array) and ignore the rest of the information?

    $.getJSON("example.json", function(data) { 
var name = data.person.name;
var id = data.person.id;
var age = data.person.age;
}

javascript表到底是什么意思 您可以通过

what do exactly mean by a javascript table u can store in a html table by

var $table = $("<table>
<tr><td>name</td><td>"+name+"</td></tr>
<tr><td>id</td><td>"+id+"</td></tr>
<tr><td>age</td><td>"+age+"</td></tr>
</table>");