using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Runtime.Serialization.Json;
using System.IO;
using System.Text.RegularExpressions;
using System.Text; namespace WebApplication1 {
public partial class WebForm2 : System.Web.UI.Page {
protected void Page_Load(object sender, EventArgs e) {
if (!IsPostBack) {
DataContractJsonSerializer JsonModel = new DataContractJsonSerializer(typeof(Person));
DataContractJsonSerializer JsonModels = new DataContractJsonSerializer(typeof(List<Person>));
MemoryStream MS1 = new MemoryStream();
Person Pone = new Person()
{ Age = , Name = "my", CreateTime = DateTime.Now.AddHours(), BisFinish = false };
Person Ptwo = new Person()
{ Age = , Name = "you", CreateTime = DateTime.Now.AddDays(), BisFinish = true };
JsonModel.WriteObject(MS1, Pone);
string JsonOnePerson = Encoding.UTF8.GetString(MS1.ToArray()); List<Person> Parr = new List<Person>();
Parr.Add(Pone); Parr.Add(Ptwo);
MemoryStream MS2 = new MemoryStream();
JsonModels.WriteObject(MS2, Parr);
string JsonPersons = Encoding.UTF8.GetString(MS2.ToArray()); ConvJsonDate(JsonPersons);
ConvJsonDate(JsonOnePerson); Response.Write(string.Format("<input id=\"Hidden1\" type=\"hidden\" value='{0}' />",
ConvJsonDate(JsonPersons)));
}
} public string ConvJsonDate(string str) {
Regex Reg = new Regex(@"\\/Date\((\d+)\+(\d+)\)\\/");
foreach (Match item in Reg.Matches(str)) {
string strOld = item.Value.Replace("\\/Date(", "").Replace("+0800)\\/", ""); string strNew;
DateTime DT = new DateTime(, , );
strNew = DT.AddMilliseconds(double.Parse(strOld)).ToLocalTime().ToString("yy-MM-dd HH:mm:ss");
str = str.Replace(item.Value, strNew);
}
return str;
}
}
public class Person {
public string Name { get; set; }
public int Age { get; set; }
public DateTime CreateTime { get; set; }
public bool BisFinish { get; set; }
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="WebApplication1.WebForm2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" language="javascript" src="Scripts/json2.js"></script>
<title></title>
</head>
<body>
<form id="form1" method="get" runat="server">
<div>
</div>
</form>
<script language="javascript" type="text/javascript">
orderListJson = {};
orderListJson = eval("(" + document.getElementById("Hidden1").value + ")");
for (var i = 0; i < orderListJson.length; i++) {
var obj = orderListJson[i];
}
</script>
</body>
</html>

asp.net JSON(一)的更多相关文章

  1. ASP输出JSON数据及客户端jQuery处理方法

    首先ASP处理JSON需要json官方提供的JSON For ASP 封装类文件,下载地址:http://code.google.com/p/aspjson/downloads/list 下载最新的J ...

  2. Asp中JSON的使用

    我对asp全然不懂,因为须要使用json的结构,就研究了一下asp的json的使用,拼接一个json的字符串. 測试用例中使用到了一个lib文件: Json_2.0.3.asp <% ' ' V ...

  3. ASP生成JSON数据

    原文地址为:ASP生成JSON数据 < %@LANGUAGE = " VBSCRIPT "  CODEPAGE = " 65001 " % >    ...

  4. ASP获取json天气信息

    ASP代码(ASP获取页面源码方法,有编码.超时时间参数,处理了乱码.超时的问题): Function GetHttpPage(HttpUrl) Then GetHttpPage="$Fal ...

  5. asp.net json 与xml 的基础事例

    //json序列化和反序列化 using System.Runtime.Serialization.Json; public static string JsonSerializer<T> ...

  6. Asp.net Json数据解析的一种思路

    在日常的编码中,经常会遇到JSON类型的数据,有简单的,也有复杂的.对于简单的,我们可以用正则等匹配,但是一旦遇到复杂的,就比较难办了. 数据分析 目前手头上需要制作一个天气预报功能,现成的接口已经有 ...

  7. Asp.net Json 解析 与 直接用ip访问返回josn

    数据分析 目前手头上需要制作一个天气预报功能,现成的接口已经有了.我随便输入一个城市,然后出现了如下的信息: {"wdata":{"cityName":&quo ...

  8. ASP.NET JSON的序列化和反序列化 之 Newtonsoft.Json

    我们用到的类库为:Newtonsoft.Json,通过VS工具中NuGet程序包可以下载. 一:对象转json-序列化 public class Student { public int ID { g ...

  9. asp.net Json序列化

    Json作为一种数据传输格式与标准被广泛的使用在项目开发中,可以说简直离不开它.那么怎么来生成JSON格式的数据就成了我们首先需要解决的问题这里我们使用.net. 首先是获取数据 public ban ...

随机推荐

  1. VS2010中配置C#Project不生成.vhost.exe和.pdb文件的方法

    在VS2010中编译C#工程时,在C#的Project的属性界面的Build选项卡中当Configuration : Relese 时,依然会生成扩展名为.vhost.exe和.pdb文件. 其中.p ...

  2. thinkphp3.2 代码生成并点击验证码

    本人小菜鸟一仅仅.为了自我学习和交流PHP(jquery,linux,lamp,shell,javascript,server)等一系列的知识.小菜鸟创建了一个群.希望光临本博客的人能够进来交流.寻求 ...

  3. 中文乱码?不,是 HTML 实体编码!(转)

    在 如何用 Nodejs 分析一个简单页面 一文中,我们爬取了博客园首页的 20 篇文章标题,输出部分拼接了一个字符串: var $ = cheerio.load(sres.text); var an ...

  4. Spring 的@Scheduled注解实现定时任务运行和调度

    Spring 的@Scheduled注解实现定时任务运行和调度 首先要配置我们的spring.xml   ---  即spring的主配置文件(有的项目中叫做applicationContext.xm ...

  5. error C2871: &#39;std&#39; : does not exist or is not a namespace

    #include <iostream.h> using namespace std; 然后编译时出现 error C2871: 'std' : does not exist or is n ...

  6. Visual Studio Team Services使用教程--邀请团队成员

  7. js 网上见到的动画函数 备份

    <script> function startMove(obj,json,fn){ clearInterval(obj.timer); obj.timer = setInterval(fu ...

  8. 8年,属于 HTML 5 春天的到来悄悄!

    [核心提示] 在 8 年时间中,HTML 5 为整个行业都带来了什么.标准终于确定后又会产生什么样的变革呢? 微博微信Twitter对于非常多人来说,非常有可能在微信的朋友圈里玩过「围住神经猫」,也非 ...

  9. rm-rf 恢复过程中滥用

    多DBA一定rm -rf讨厌它,也许有一天自己将数据库,以消除一个中午,然后.那么就没有一个--这种情况下,--这个不幸真的发生,你真的无药可救?不必要,有解决方法.也许你遇到不幸时,有一天.你可以用 ...

  10. vs2010公布时去除msvcp100.dll和msvcr100.dll图讲解明

    近期开发个程序,Copy到虚拟机环境中測试时提示缺少msvcr100.dll,于是想到编译时设置选项去除依赖. 什么是 msvcr100.dll MS = Microsoft V = Visual C ...