反序列化json服务器端 [英] deserialise json server side
本文介绍了反序列化json服务器端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何反序列化从javascript(使用jquery.ajax)发送到.aspx页面(而不是Web服务)的json对象?
How can I de-serialize a json object sent from javascript (using jquery.ajax) to a .aspx page (not a web service)?
例如如果我有以下json对象;
e.g. if I have the following json object;
var json = {"name" : "michael", "surname" : "brown", "age" : "35"}
我用
$.post('process.aspx', json)
我如何反序列化后面process.aspx代码中的json?
how do I get to deserialize the json in process.aspx code behind?
还,如何使用$ .postJSON()?
also, how do I use the $.postJSON() in my case?
推荐答案
您可以使用 http ://jayrock.berlios.de/
要使用DataContractJsonSerializer,您的代码可能看起来像这样:
To use the DataContractJsonSerializer, your code might look something like this:
var serializer = new DataContractJsonSerializer(typeof(Person));
using (MemoryStream ms = new MemoryStream(new ASCIIEncoding().GetBytes(myString)))
{
try
{
Person obj = serializer.ReadObject(ms) as Person;
}
catch (Exception e)
{
throw new InvalidOperationException("Could not deserialize Person.", e);
}
}
这篇关于反序列化json服务器端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文