在ASP.NET页面中将.json文件中的数据显示为表格形式 [英] display data from .json file to tabular form in ASP.NET page
本文介绍了在ASP.NET页面中将.json文件中的数据显示为表格形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
I've to show the data in a table importing the data from a JSON file. I can not proceed further with this. Since I am new to asp.net, do not how to display the imported data in a table in ASP.NET.
//// json file
{"employees":[
{"firstName":"Anna","lastName":"Meyers"},
{"firstName":"Betty","lastName":"Layers"},
{"firstName":"Carl","lastName":"Louis"},
]}
<%@ Page Title="About" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="About.aspx.cs" Inherits="ReadDataJSON.About" %>
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="jquery-1.10.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#Result").click(function() {
$.ajax({
type: "GET",
url: "C:\Users\NISCHALINN\Documents\test.json",
beforeSend: function() {
$.blockUI({
fadeIn : 0,
fadeOut : 0,
showOverlay : false
});
},
dataType: "json",
success: function(data)
{
alert(data);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
},
complete: function ()
{
$.unblockUI();
}
});
});
});
</script>
<h2><%: Title %>.</h2>
<h3>Your application description page.</h3>
<h4>JSON Object Creation in JavaScript</h4>
<p>Use this area to provide additional information.</p>
<div>
<% ------- display the JSON data in tabular format ------ %>
</div>
</asp:Content>
输出格式为:
The output format is:
FirstName LastName
------------------
Anna Meyers
Betty Layers
Carl Louis
------------------
我该怎么做?请帮助我,我是ASP.NET新手。
问候!
How can I do this? Please help me I am new to ASP.NET.
Regards!
推荐答案
( document )。ready( function (){
(document).ready(function() {
( #Result)。click( function (){
("#Result").click(function() {
.ajax({
type: GET,
url: C:\ Users \ NISCHALINN \ Document \ test.json ,
beforeSend: function (){
.ajax({ type: "GET", url: "C:\Users\NISCHALINN\Documents\test.json", beforeSend: function() {
这篇关于在ASP.NET页面中将.json文件中的数据显示为表格形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文