如何将JSON数据存储为JavaScript表格式? [英] How to store JSON data into JavaScript table format?

查看:97
本文介绍了如何将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>");

这篇关于如何将JSON数据存储为JavaScript表格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆