如何用JavaScriptserializer.jar

二次元同好交流新大陆
扫码下载App
汇聚2000万达人的兴趣社区下载即送20张免费照片冲印
扫码下载App
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!&&|&&
LOFTER精选
网易考拉推荐
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
反序列化string str1 = "{\"ID\":1,\"Name\":\"张三\",\"Time\":\"\\/Date(1)\\/\"}";//反序列化成功string str2 = "{\"ID\":1,\"Name\":\"张三\"}";//反序列化成功string str3= "{\"ID\":1,\"Name\":\"张三\",\"Time\":\"\"}";//反序列化成功OneObj second = str3
.JsonDeserialezer&OneObj&();Console.WriteLine(second.Name);Console.WriteLine(second.Time);object obj = str3.JsonDeserialezer&object&();Console.WriteLine(obj.ToJsonString());dynamic obj2 = str3.JsonDeserialezer&dynamic&();Console.WriteLine(obj2["Name"]);Dictionary&string, string& dic = str3.JsonDeserialezer&Dictionary&string, string&&();Console.WriteLine(dic["Name"]);string str4 = "[{\"ID\":1,\"Name\":\"张三\",\"Time\":\"\"},{\"ID\":1,\"Name\":\"张三\",\"Time\":\"\"}]";//反序列化成功Dictionary&string, string&[] dic2 = str4.JsonDeserialezer&Dictionary&string, string&[]&();foreach (var item in dic2){
Console.WriteLine(item["Name"]);}
&class People&&& {&&&&&&& public int Id { }&&&&&&& public string Name { }&&&&&&& public DateTime Age { }&&& }
序列化:List&People& list = new List&People&();&&&&&&& People peo = new People();&&&&&&& peo.Id = 1;&&&&&&& peo.Name = "zhangsan";&&&&&&& peo.Age = DateTime.N&&&&&&&& list.Add(peo);&&&&&&&& People peo2 = new People();&&&&&&&& peo2.Id = 2;&&&&&&&& peo2.Name = "lisi";&&&&&&&& peo2.Age = DateTime.N&&&&&&&& list.Add(peo2);&&&&&&& JavaScriptSerializer ser = new JavaScriptSerializer();&&&&&&& TextBox1.Text = ser.Serialize(list);
{"Id":1,"Name":"zhangsan","Age":"\/Date(8)\/"},
{"Id":2,"Name":"lisi","Age":"\/Date(8)\/"}
反序列化:
&string json = TextBox1.T&&&&&&& JavaScriptSerializer ser=new JavaScriptSerializer();&&&&&&& List&People& list = ser.Deserialize&List&People&&(json);&&&&&&& foreach (People peo in list)&&&&&&& {&&&&&&&&&&& Response.Write(peo.Name + "&br&" + peo.Id + "&br&" + peo.Age);&&&&&&&&&&& Response.Write("&hr&");&&&&&&& }
前台脚本解析:
$(":submit:eq(2)").click(function () {&&&&&&&&&&&&&&& //&&&&&&&&&&&&&&& $.getJSON("../logic/October.ashx", { code: "one" }, function (data) {&&&&&&&&&&&&&&&&&&& $.each(data, function (key, val) {&&&&&&&&&&&&&&&&&&&&&&& $("p").append(key + "---&&" + val + "&br&");&&&&&&&&&&&&&&&&&&&&&&& $.each(val, function (k, v) {&&&&&&&&&&&&&&&&&&&&&&&&&&& $("h5").append(k+"----&&"+v+"&hr&");&&&&&&&&&&&&&&&&&&&&&&& });&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& });&&&&&&&&&&&&&&& });&&&&&&&&&&&&&&&&&&&&&&&&&& });
阅读(2503)|
用微信&&“扫一扫”
将文章分享到朋友圈。
用易信&&“扫一扫”
将文章分享到朋友圈。
历史上的今天
在LOFTER的更多文章
loftPermalink:'',
id:'fks_',
blogTitle:'Asp.Net中JSON的序列化和反序列化-----JavaScriptSerializer',
blogAbstract:'命名空间:\n&&&&&&& ASP.NET中的JSON序列化和反序列化还可以使用JavaScriptSerializer,在System.Web.Script.Serializatioin命名空间下,需引用System.Web.Extensions.dll.实例2:序列化
public class OneObj
public int ID { }
public string Name { }
public DateTime Time { }
blogTag:'json序列化',
blogUrl:'blog/static/',
isPublished:1,
istop:false,
modifyTime:3,
publishTime:4,
permalink:'blog/static/',
commentCount:1,
mainCommentCount:1,
recommendCount:0,
bsrk:-100,
publisherId:0,
recomBlogHome:false,
currentRecomBlog:false,
attachmentsFileIds:[],
groupInfo:{},
friendstatus:'none',
followstatus:'unFollow',
pubSucc:'',
visitorProvince:'',
visitorCity:'',
visitorNewUser:false,
postAddInfo:{},
mset:'000',
remindgoodnightblog:false,
isBlackVisitor:false,
isShowYodaoAd:false,
hostIntro:'',
hmcon:'0',
selfRecomBlogCount:'0',
lofter_single:''
{list a as x}
{if x.moveFrom=='wap'}
{elseif x.moveFrom=='iphone'}
{elseif x.moveFrom=='android'}
{elseif x.moveFrom=='mobile'}
${a.selfIntro|escape}{if great260}${suplement}{/if}
{list a as x}
推荐过这篇日志的人:
{list a as x}
{if !!b&&b.length>0}
他们还推荐了:
{list b as y}
转载记录:
{list d as x}
{list a as x}
{list a as x}
{list a as x}
{list a as x}
{if x_index>4}{break}{/if}
${fn2(x.publishTime,'yyyy-MM-dd HH:mm:ss')}
{list a as x}
{if !!(blogDetail.preBlogPermalink)}
{if !!(blogDetail.nextBlogPermalink)}
{list a as x}
{if defined('newslist')&&newslist.length>0}
{list newslist as x}
{if x_index>7}{break}{/if}
{list a as x}
{var first_option =}
{list x.voteDetailList as voteToOption}
{if voteToOption==1}
{if first_option==false},{/if}&&“${b[voteToOption_index]}”&&
{if (x.role!="-1") },“我是${c[x.role]}”&&{/if}
&&&&&&&&${fn1(x.voteTime)}
{if x.userName==''}{/if}
网易公司版权所有&&
{list x.l as y}
{if defined('wl')}
{list wl as x}{/list}JSON.NET JsonConvert vs .NET JavaScriptSerializer - Stack Overflow
to customize your list.
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.
J it only takes a minute:
Join the Stack Overflow community to:
Ask programming questions
Answer and help your peers
Get recognized for your expertise
What is better to use when it comes to encoding and decoding of JSON in .NET? I have tried both and upto this point JsonConvert seems to be doing a good job. I have used JavaScriptSerializer in the past successfully but have had some problems in the recent past with it. Is it better to use JSON.NET than the .NET class?
What are the preferred functions for encoding/decoding json using the appropriate library? I use SerializeObject/DeSerializeObject from JSON.NET and Serialize/DeSerialize from .NET.
1,55021443
I don't have enough rep to comment yet so had to post this as an answer. I think
is exactly the kind of comparison you are looking for.
It basically says that JSON.Net is better because it among other things...
Has LINQ to JSON support
Can convert JSON to and from XML
In my opinion the only positive, (and it is a small positive), I can see for the built-in serializer is that there is no extra external dependency to manage.
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled如何用JavaScriptSerializer_百度知道
如何用JavaScriptSerializer
提问者采纳
Customer c1 = ScriptDeserialize(strJson),采用相同的映射;
return js,此类公开了公共 API.W方法来实现.Extensions库文件引用参考实体类、JavaScriptSerializer 类由异步通信层内部使用;Customer& &quot.WriteLine(c1; }.Serialization如果要使用它:Customer cc = new Customer { Unid = 1.WriteLine(strJson),用于将对象转换为 JSON 字符串public string ScriptSerialize(Customer customer)
JavaScriptSerializer js = new JavaScriptSerializer()、通过JavaScriptSerializer来实现:public string Serialize(Object obj);
Console。JavaScriptSerializer 本身支持这些托管类型:Customerpublic class Customer{
public int Unid { get。但是;Console,请使用 Deserialize 或 DeserializeObject 方法; }}类JavaScriptSerializer描述。然后.WJohn&quot。它的名字空间为.Deserialize&
}测试,使用 RegisterConverters 方法注册转换器.S set,当您希望在托管代码中使用 JavaScript 对象符号 (JSON) 时可以使用此类;
return js,用于序列化和反序列化在浏览器和 Web 服务器之间传递的数据一;T&gt:为启用 AFAX 的应用程序提供序列化和反序列化功能;(二)反序列化public Customer ScriptDeserialize(string strJson)
JavaScriptSerializer js = new JavaScriptSerializer()。若要序列化对象。若要反序列化 JSON 字符串。测试。二:System,反序列化可能是非对称的;(strJson).Unid + &quot,还须添加System, CustomerName = &
}通过Deserialize&lt。(一) 序列化方法。将 JSON 字符串反序列化为托管类型时。若要序列化和反序列化 JavaScriptSerializer 本身不支持的类型; + c1.Serialize(customer); }
public string CustomerName { get,请使用 JavaScriptConverter 类来实现自定义转换器,请使用 Serialize 方法,并非所有可序列化的托管类型都可以从 JSON 反序列化得到。托管类型和 JSON 之间的映射下表显示序列化进程中托管类型和 JSON 之间的映射。您无法访问序列化程序的此实例;
string strJson = ScriptSerialize(cc)。但是。因此
来自团队:
其他类似问题
为您推荐:
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 maxJsonLength 属性设置的值问题
[问题点数:20分,结帖人nitaiyoucala]
使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错,字符串的长度超过了为 maxJsonLength 属性设置的值问题
[问题点数:20分,结帖人nitaiyoucala]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。JavaScriptSerializer问题
[问题点数:40分,结帖人dengixnyu]
JavaScriptSerializer问题
[问题点数:40分,结帖人dengixnyu]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
2014年2月 .NET技术大版内专家分月排行榜第二
2014年4月 .NET技术大版内专家分月排行榜第三2014年3月 .NET技术大版内专家分月排行榜第三2013年10月 .NET技术大版内专家分月排行榜第三
2014年2月 .NET技术大版内专家分月排行榜第二
2014年4月 .NET技术大版内专家分月排行榜第三2014年3月 .NET技术大版内专家分月排行榜第三2013年10月 .NET技术大版内专家分月排行榜第三
2011年4月 .NET技术大版内专家分月排行榜第二
2011年3月 .NET技术大版内专家分月排行榜第三
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。}

我要回帖

更多关于 jsonserializer使用 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信