前台一个json数组:
var jsonObj2={persons:[{name:"jordan",sex:"m",age:"40"}, 
{name:"bryant",sex:"m",age:"28"}, 
{name:"McGrady",sex:"m",age:"27"} 
]}; 
到后台保存时我怎么把这个json数组转化为后台的数据
也就是到后台取到这个json数组的值

解决方案 »

  1.   

    - -jquery ajax() post 过去
      

  2.   

     .net 有直接json操作是转换数据的没? 
     如果没有, 那就优先{persons:[{ 跟最后一个]} 去掉, 
    然后使用},{ split 开, 再一个字符串 分隔. 分隔...  这是我的想法..
      

  3.   

    到网上下这个库:Newtonsoft.Json.dll用法和XML那个操作类差不多,参考如下:
    注意:这个是将后台数据转成Json数组,你反过来就是的了!
                //构建JSon对象           
                StringWriter text = new StringWriter();
                JsonWriter json = new JsonWriter(text);
                json.Formatting = Formatting.Indented;
                json.WriteStartArray();
                for (int i = 0; i < data.Tables[0].Rows.Count; i++)
                {
                    DataRow currRow = data.Tables[0].Rows[i];
                    
                    json.WriteStartObject();
                    //简历ID
                    json.WritePropertyName("rid");
                    json.WriteValue(Convert.ToInt32(currRow["id"]));
                    //求职者姓名
                    PersonalInfo pinfo = new PersonalInfo();
                    int mid = Convert.ToInt32(currRow["mid"]);
                    DataSet temp = pinfo.QueryPersonalInfoByUid(mid);
                    json.WritePropertyName("realName");
                    json.WriteValue(temp.Tables[0].Rows[0]["realName"].ToString());
                    //求职者ID
                    json.WritePropertyName("mid");
                    json.WriteValue(mid.ToString());
                    //性别
                    int str_sex = Convert.ToInt32(temp.Tables[0].Rows[0]["sex"]);
                    json.WritePropertyName("sex");
                    if (str_sex == 1) json.WriteValue("男");
                    else json.WriteValue("女");                    
                    //年龄
                    DateTime birthday = Convert.ToDateTime(temp.Tables[0].Rows[0]["birthday"]);
                    int age = DateTime.Now.Year - birthday.Year;
                    json.WritePropertyName("age");
                    json.WriteValue(age.ToString());
                    //学历
                    string str_education = temp.Tables[0].Rows[0]["education"].ToString();
                    item = category.QueryCategoryById(str_education);
                    json.WritePropertyName("education");
                    json.WriteValue(item.Tables[0].Rows[0]["cName"].ToString());
                    //行业职位
                    string str_workIndustry = currRow["workIndustry"].ToString();
                    item = category.QueryCategoryById(str_workIndustry);                
                    string industry_job = item.Tables[0].Rows[0]["cName"].ToString() + "-";
                    string str_workJob = currRow["workJob"].ToString();
                    item = category.QueryCategoryById(str_workJob);
                    industry_job += item.Tables[0].Rows[0]["cName"].ToString();
                    json.WritePropertyName("job");
                    json.WriteValue(industry_job);
                    //工作经验
                    string str_workAge = currRow["workAge"].ToString();
                    item = category.QueryCategoryById(str_workAge);
                    json.WritePropertyName("workAge");
                    json.WriteValue(item.Tables[0].Rows[0]["cName"].ToString());
                    //简历公开程度
                    string str_openness = currRow["openness"].ToString();
                    item = category.QueryCategoryById(str_openness);
                    json.WritePropertyName("openness");
                    json.WriteValue(item.Tables[0].Rows[0]["cName"].ToString());                
                                    
                    json.WriteEndObject();
                }
                json.WriteEndArray();
      

  4.   

    $.ajax({
      type: "POST",
      url: "handler.ashx",
      data: "",
      dataType:"json",
    ..
     });  context.Request.Form["name"];