ASP.NET ashx文件如何客户端提交的JSON字符串转换成JSON对象然后把值读出来? 50

如何把一下JSON读出来(代码详细一点家悬赏)stringJson={"people":[{"firstName":"Brett","lastName":"McLaugh... 如何把一下JSON读出来(代码详细一点家悬赏)
string Json = { "people": [{ "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },{ "firstName":"Jason","lastName":"Hunter", "email": "bbbb"},{ "firstName": "Elliotte", "lastName":"Harold","email": "cccc" }]}
展开
 我来答
bai404844226
2013-07-26 · TA获得超过282个赞
知道小有建树答主
回答量:235
采纳率:0%
帮助的人:125万
展开全部
using System.Runtime.Serialization.Json;

public class infoObject
{
public String name { get; set; }
public String birthday { get; set; }
public String id { get; set; }
public String email { get; set; }

public infoObject()
{
name = "";
birthday = "";
id = "";
email = "";
}

public infoObject(String newname, String newbirthday, String newid, String newemail)
{
name = newname;
birthday = newbirthday;
id = newid;
email = newemail;
}

}
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
infoObject info = new infoObject("peng","19920412","342423188209121234","12312@qq.com");
string szJson;
//将对象转成字符串
DataContractJsonSerializer json = new DataContractJsonSerializer(info.GetType());
using (MemoryStream stream = new MemoryStream())
{
json.WriteObject(stream, info);//把对象填充到流里(关键)
szJson = Encoding.UTF8.GetString(stream.ToArray());//按指定格式把流编码成字符串
Response.Write( "对象转成字符串:<br>"+szJson+"<br>");
}

//将字符串转成对象
//infoObject obj = Activator.CreateInstance<infoObject>();
infoObject obj = new infoObject();
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(szJson)))
{
DataContractJsonSerializer serializer = new DataContractJsonSerializer(obj.GetType());
obj=(infoObject)serializer.ReadObject(ms);//将含有字符串的流转成对象
}
Response.Write("字符串转对象:"+obj.name + "<br>" + obj.birthday + "<br>" + obj.id + "<br>" + obj.email);
}
}
百度网友115a69b
2013-07-26 · TA获得超过253个赞
知道小有建树答主
回答量:428
采纳率:50%
帮助的人:383万
展开全部
jsonSerialization,JavaScriptSerializer自已百度吧.
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式