ASP.NET ashx文件如何客户端提交的JSON字符串转换成JSON对象然后把值读出来?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ASP.NET ashx文件如何客户端提交的JSON字符串转换成JSON对象然后把值读出来?相关的知识,希望对你有一定的参考价值。
如何把一下JSON读出来(代码详细一点家悬赏)
string Json = "people": [ "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" , "firstName":"Jason","lastName":"Hunter", "email": "bbbb", "firstName": "Elliotte", "lastName":"Harold","email": "cccc" ]
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);
参考技术A jsonSerialization,javascriptSerializer自已百度吧.
asp.net 一般处理程序(ashx)如何多次接收上传文件(多文件批量上传)
aspx页面能接受 调试时候能多次调用,而一般处理程序不能
参考技术A Likethis
:
比如前台有3个INPUT:
然后后台:
HttpFileCollection
files
=
HttpContext.Current.Request.Files;
//这个files里面就是你上传文件的集合。遍历即可。
以上是关于ASP.NET ashx文件如何客户端提交的JSON字符串转换成JSON对象然后把值读出来?的主要内容,如果未能解决你的问题,请参考以下文章
ASP.NET前台html页面AJAX提交数据后台ashx页面接收数据
asp.net 一般处理程序(ashx)如何多次接收上传文件(多文件批量上传)