解决方案 »
- 请问有没有比较好的开源.net网店程序??
- c#中label.text怎么重写
- 在同一个页面上放置多个GRIDVIEW, 会不会有效率问题?
- 在一个页面中调用另一个页面的方法,如果不知道该方法的位置,怎样从该方法的调用处找到其声明处呢?举例说明如下:
- 如何使用ASP.NET 传输 POST 数据?
- 一个关于服务器时间的问题?
- 动态添加控件的问题
- 求一javascript(两级DataList嵌套中的checkbox,有兴趣的兄弟们过来看看哟)
- 简单的问题, 我能否在某下操作后先弹出个对话框,然后转向另外个页面
- 为什么用文本编辑和用VS.NET编辑会存在这么大的不同
- .net 数字转字母
- EXCEL导出并提示保存(asp.net B/S架构希望给完整的源代码)
"strJson"为RoleFunc.aspx/Convert的参数名称,这里的json为字符串就可以了
感谢昨天对我的回复,这个。我已经尝试过.但是它提示
Invalid JSON primitive: strJson
02. type: "POST",
03. url: "WebService.asmx/WebMethodName",
04. data: <span style="color: rgb(255, 102, 102);">"</span>{'fname':'dave', 'lname':'ward'}<span style="color: rgb(255, 0, 0);">"</span>,
05. contentType: "application/json; charset=utf-8",
06. dataType: "json"
07.});
var strJson = { Users: [{ Id: 1, Name: "Ahoo1" }, { Id: 2, Name: "Ahoo2"}] }
var url="@Url.Action("DesJson")";
$.ajax({
url: url,
dataType: "json",
data: { json: JSON.stringify(strJson.Users) },//将数组对象持久化为string
success: function (data) {
alert(data);
},
error: function (data) {
alert(data);
}
}); public JsonResult DesJson(string json)
{
IList<DataDemo> datas = Newtonsoft.Json.JsonConvert.DeserializeObject<IList<DataDemo>>(json);//使用Newtonsoft 反序列化
return Json(datas, JsonRequestBehavior.AllowGet);
}
遗漏了 实体类[DataDemo] public class DataDemo
{
public int Id { get; set; }
public string Name { get; set; }
}
//var json = { "menu": [{ "Role_ID": "2", "Customer_ID": "155", "Brands": "Chloe", "Country_ID": "96" }, { "Role_ID": "-1", "Customer_ID": "497", "Brands": "Chloe", "Country_ID": "96"}] };
$.ajax({
url: "test_ajax.aspx/Convert",
type: "POST",
contentType: "application/json",
data: '{ "strJson":'+ _json +'}',
success: function (result) {
alert(result.d);
},
error: function () {
alert("error");
}
});
感谢昨天对我的回复,这个。我已经尝试过.但是它提示
Invalid JSON primitive: strJson这个的原因应该是你写了contentType: "application/json",需要返回一个json格式的字符串应该是这样吧~~
$.ajax({
url: "test_ajax.aspx/Convert",
type: "POST",
contentType: "application/json",
data: '{ "strJson":' + json + '}',
success: function (result) {
alert(result.d);
},
error: function () {
alert("error");
}
});
感谢昨天对我的回复,这个。我已经尝试过.但是它提示
Invalid JSON primitive: strJson这个的原因应该是你写了contentType: "application/json",需要返回一个json格式的字符串应该是这样吧~~
这个是提交的格式,是你请求的格式问题,直接把这个contentType整个干掉,它自己有默认的,data直接传{"strJson":json},里面的冒号打不打是一样的。然后后台接收(string strJson)
{
public string Role_ID { get; set; }
public string Customer_ID { get; set; }
public string Brands { get; set; }
public string Country_ID { get; set; }
}
public class CustomerShell
{
public CustomerRole[] menu;
}
var json = @"{""menu"":[{""Role_ID"":""2"",""Customer_ID"":""155"",""Brands"":""Chloe;"",""Country_ID"":""96;""},{""Role_ID"":""-1"",""Customer_ID"":""497"",""Brands"":""Chloe;"",""Country_ID"":""96;""}]}";
CustomerShell obj = (CustomerShell)new DataContractJsonSerializer(typeof(CustomerShell)).ReadObject(new MemoryStream(Encoding.UTF8.GetBytes(json)));