展开全部
如果你的json是以字符串参数的形式传到ashx,你可以在ashx接收参数并反序列化为一个自定义的对象
//反序列化
public static T FromJsonTo<T>(string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
{
T jsonObject = (T)ser.ReadObject(ms);
return jsonObject;
}
}
如果不是这样当前台传输类似这样(你的json前面差一个属性名,我加了个people):
people:[{"uid":35301,"uname":"%u9EC4%u8363"},
{"uid":437,"uname":"%u6211%u884C%u5BA2%u670D"}]
则在ashx里需要这么取:
string a = context.Request.Form["people[0][uid]"].ToString();
context.Response.Write(a);
//反序列化
public static T FromJsonTo<T>(string jsonString)
{
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(T));
using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
{
T jsonObject = (T)ser.ReadObject(ms);
return jsonObject;
}
}
如果不是这样当前台传输类似这样(你的json前面差一个属性名,我加了个people):
people:[{"uid":35301,"uname":"%u9EC4%u8363"},
{"uid":437,"uname":"%u6211%u884C%u5BA2%u670D"}]
则在ashx里需要这么取:
string a = context.Request.Form["people[0][uid]"].ToString();
context.Response.Write(a);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询