在一个MVC控制器有这样的代码
[HttpPost]
public JsonResult Gett_001_SQL()

  //字符串赋值
  string m = "{total: 9,page: 1,records: 17,  rows : [ {id:'1', cell:[ '1','FG001','SFG001','1.000000','2013-04-02 0:00:00' ] },{id:'2', cell:[ '2','FG001','SFG002','1.000000','2013-02-01 0:00:00' ] } ] }";
  var json = Json(m);  //将字符串转换成JSON格式
  return json;         //返回给客户端
}
客户端接收到的信息为
"{total: 9,page: 1,records: 17,  rows : [ {id:\u00271\u0027, cell:[ \u00271\u0027,\u0027FG001\u0027,\u0027SFG001\u0027,\u00271.000000\u0027,\u00272013-04-02 0:00:00\u0027 ] },{id:\u00272\u0027, cell:[ \u00272\u0027,\u0027FG001\u0027,\u0027SFG002\u0027,\u00271.000000\u0027,\u00272013-02-01 0:00:00\u0027 ] } ] }"
为什么会这样啊? 
服务端要怎么修改才对啊?

解决方案 »

  1.   

    把单引号都去掉. json就是个字符串,没有必要用单引号吧.
      

  2.   

    因为你传的json,不是字符串,最好还是转一下在接收使用。
    利用JavaScriptSerializer序列化类解析 
     JavaScriptSerializer ser = new JavaScriptSerializer();
     组装好的对象 foo= ser.Deserialize<对象类型>(json_);
      

  3.   

    findcaiyzh  把单引号去掉,服务端代码改成
      string m="{total: 9,page: 1,records: 17,  rows : [ {id:1, cell:[ 1,FG001,SFG001,1.000000,2013-04-02 0:00:00 ] },{id:2, cell:[ 2,FG001,SFG002,1.000000,2013-02-01 0:00:00 ] } ] }"
      var json = Json(m);  //将字符串转换成JSON格式
      return json; 客户端接收到的信息变成
      "{total: 17,page: 1,records: 17,  rows : [ {id:1, cell:[ 1,FG001,SFG001,1.000000,2013-04-02 0:00:00 ] } ] }"
    客户端认为它是一个字符串,而不是JSON
      
      

  4.   

    u010037549
      服务端有进行转换的var json = Json(m);  ===>这里就是在转换.
      

  5.   

    如果直接抛出字符串用这种
    public ContentResult ActionName(){
        return Content("{\"statusCode\":\"300\",\"message\":\"消息\"}");
    }
    是对象的话
    public JsonResult ActionName(){
        JsonResult jr = new JsonResult();
        jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        jr.Data = obj;
        return jr;
    }
      

  6.   

    zhangshaohua01
      按你这样改更不行了
      public JsonResult Gett_001_SQL()

      //字符串赋值
      string m = "{total: 9,page: 1,records: 17,  rows : [ {id:'1', cell:[ '1','FG001','SFG001','1.000000','2013-04-02 0:00:00' ] },{id:'2', cell:[ '2','FG001','SFG002','1.000000','2013-02-01 0:00:00' ] } ] }";
      var json = Json(m);  //将字符串转换成JSON格式
      
      JsonResult jr = new JsonResult();
        jr.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
        jr.Data = json;
        return jr;
    }客户端接收变成了
    {"ContentEncoding":null,"ContentType":null,"Data":"{total: 9,page: 1,records: 17,  rows : [ {id:\u00271\u0027, cell:[ \u00271\u0027,\u0027FG001\u0027,\u0027SFG001\u0027,\u00271.000000\u0027,\u00272013-04-02 0:00:00\u0027 ] },{id:\u00272\u0027, cell:[ \u00272\u0027,\u0027FG001\u0027,\u0027SFG002\u0027,\u00271.000000\u0027,\u00272013-02-01 0:00:00\u0027 ] } ] }","JsonRequestBehavior":1,"MaxJsonLength":null,"RecursionLimit":null}
      

  7.   

    a407121393
    var json = Json(m);  ===>这行代码不就是将字符串转换成JSON对象吗?
      

  8.   

    关键应该还是错在String转JSON的方法中, 不知道谁有比较好的string转JSON方法
      

  9.   

    哥你QQ多少我想问一下你dwz框架的上传文件的功能