JavaScript

JavascriptSerializer与匿名对象

时间:2014-3-19 13:07:59  作者:WPF之家  来源:http://www.wpf123.com/  查看:1207  评论:0
内容摘要:一:匿名对象语法: var result = new { UserName = u.Alias, Email = u.Email, Mobile = u.M...

一:匿名对象语法:

复制代码
 var result = new             {
                UserName = u.Alias,
                Email = u.Email,
                Mobile = u.Mobile,
                OfficePhone = u.OfficePhone,
                Fax = u.FacsimileTelephoneNumber,
                HasPicture=(u.Picture!=null&&u.Picture.Length>0)?true:false             };
复制代码

二:JavascriptSerializer

jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
JSSerializer.Serialize(result)

 通过此操作生成客户端json格式数据

三:客户端得到json数据

var data=eval("("+data+")");

标签:匿名 对象 

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。本文出自“wpf之家”,请务必保留此出处:http://www.wpf123.com

相关评论
Copyright © 2009-2014 WPF之家(http://www.wpf123.com/) All rights reserved
 Powered by WPF之家
鄂ICP备13006396号