The following is a really minimalistic approach, assuming an asp.net project from the VS template.
Code behind:
Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace WebApplication1
{
public partial class _Default : System.Web.UI.Page
{
public sealed class Person
{
public int ID { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
protected IList<person> persons = new List<person>();
protected void Page_Load(object sender, EventArgs e)
{
persons.Add(new Person { ID = 1, Name = "Peter", Age = 20 });
persons.Add(new Person { ID = 2, Name = "John", Age = 26 });
persons.Add(new Person { ID = 2, Name = "Olivia", Age = 23 });
}
}
}
As you can see I am defining a class, and a list from that class, not an array. And of course, not three arrays, since that is a really bad approach. So I have my data.
Now, in the
Defaul.aspx
I embed the JSON encoded representation of that object. I actually pass it to a javascript object.
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>
<asp:Content ID="ScriptContent" runat="server" ContentPlaceHolderID="HeadContent">
<script type="text/javascript">
var persons = eval('(<% Response.Write(fastJSON.JSON.Instance.ToJSON(persons)); %>)');
</script>
</asp:Content>
<asp:Content ID="MainContent" runat="server" ContentPlaceHolderID="MainContent">
<script type="text/javascript">
alert(persons);
</script>
</asp:Content>
The alert will show an array of objects. Now it is your turn to process the variable. I have downloaded and referenced
FastJSON[
^] for this code to work. Notice, that you can add a second parameter to the serializer to fine tune the serialization. Look at the generated code to see how the serialization is performed.
Well, this is not the only approach, and could be not the most suitable for your needs. But you have not specified what you want to do.