1,自定义一个json数据:
2,把这个json数据传递给后台处理
3,后台webService服务进行解析处理
[WebMethod]
public void TestJSON()
{
HttpRequest request = HttpContext.Current.Request;
string objName = request["xxx"];
List<School> list_sc = getOneJson(objName);
}
getOneJson方法:
public static List<School> getOneJson(string jsonText)
{
List<School> list = new List<School>();
javascriptSerializer js = new JavaScriptSerializer();
object obj = js.DeserializeObject(jsonText);
foreach (object item in ((object[])(js.DeserializeObject(jsonText))))
{
School model = new School();
model.Id = ((Dictionary<string, object>)item)["Id"].ToString();
model.Name = ((Dictionary<string, object>)item)["Name"].ToString();
model.NameEn = ((Dictionary<string, object>)item)["NameEn"].ToString();
model.AreaId = ((Dictionary<string, object>)item)["AreaId"].ToString();
list.Add(model);
}
return list;
}
声明一个json格式的类以方便序列化: