Asp.net_Webservice返回json
[WebMethod]
public List<PictureManager> LoadPictureOne()
{
dataDataContext context = new dataDataContext();
List<PictureManager> list = new List<PictureManager>();
try
{
List<PictureManager> li = context.PictureManager.Where(p => p.TypeId == && p.IsShow == true).OrderByDescending(p => p.Id).Take().ToList();
foreach (PictureManager item in li)
{
PictureManager tb = new PictureManager();
tb.Id = item.Id;
tb.Name = item.Name;
tb.Picture = item.Picture;
tb.Price = item.Price;
tb.PriceInfo = item.PriceInfo;
tb.Remark = item.Remark;
list.Add(tb);
}
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
return list;
}
//加载图片1
function LoadPictureOne() {
$("#div1").html("");
var htmlInfo = "";
$.ajax({
type: "post",
contentType: "application/json;charset=utf-8",
url: "../../service/backstageService.asmx/LoadPictureOne",
data: "",
dataType: "json",
success: function (result) {
var data = eval(result.d);
$(data).each(function () {
htmlInfo += "<div class='moxin'><div ><img style=\"width:223px; height:217px;\" src='../../images/PictureManager/" + this.Picture + "' alt='" + this.Name + "' /></div><ul><li><p class='wenziqj'>" + this.Price + "</p></li><li><p class='wenzish'> " + this.PriceInfo + "</p><p class='wenzixia'>" + this.Name + "</p></li><li class='tuliji' onclick='img_click(\"" + this.Name + "\")'><img src='../../images/images/qiangoguanniu.png' style='cursor:pointer' /></li></ul></div>";
});
$("#div1").html($.trim(htmlInfo));
},
error: function (err) { layer.alert("加载图片出错", ); }
});
}
如果返回的 是单个对象:
result.d的值是:"{"brxm":"aa","ys":"bb","ks":"cc","hm":"123","sj":"08:50"}"
eval("("+result.d+")")试一试。
[WebMethod]
public string GetCount()
{
string json = string.Empty;
try
{
using (dataDataContext context = new dataDataContext())
{
if (context.tb_ApplicationAward.Count() != )
{
int CountM = Convert.ToInt32(context.tb_ApplicationAward.Sum<tb_ApplicationAward>(p => p.scheduleLength));
if (CountM > )
{
CountM = ;
}
int CountPeople = context.tb_ApplicationAward.Count();
return "{'CountM':" + CountM + ",'CountPeople':" + CountPeople + "}";
}
return "{\"CountM\":" + + ",\"CountPeople\":" + + "}";
}
}
catch (Exception)
{
return null;
}
}
function Loading() {
$.ajax({
type: "post",
contentType: "application/json;charset=utf-8",
url: "../../service/backstageService.asmx/GetCount",
data: "{}",
dataType: "json",
success: function (js) {
var obj = eval('(' + js.d + ')');
var CountM = obj.CountM;//总米数
count = CountM;
var CountPeople = obj.CountPeople;//总人数
//前台取得时候是用js.d来取
Asp.net_Webservice返回json的更多相关文章
- ASP .NET 返回Json操作结果
返回string var A="..."; var B="..."; $.ajax({ type: "POST", url: "/ ...
- ASP.NET返回Json数据
Schedule.ashx: <%@ WebHandler Language="C#" Class="Schedule" %> using Syst ...
- ASP.NET Core 返回 Json DateTime 格式
ASP.NET Core 返回 Json 格式的时候,如果返回数据中有DateTime类型,如何自定义其格式呢?配置如下: services.AddMvc().AddJsonOptions(opt = ...
- ASP.NET WEB API 返回JSON 出现2个双引号问题
前言 在使用ASP.NET WEB API时,我想在某个方法返回JSON格式的数据,于是首先想到的就是手动构建JSON字符串,如:"{\"result\" ...
- ASP.net jQuery调用webservice返回json数据的一些问题
之前寒假时,试着使用jQuery写了几个异步请求demo, 但是那样是使用的webform普通页面,一般应该是用 webservice 居多. 最近写后台管理时,想用异步来实现一些信息的展示和修改, ...
- ASP.NET Web API 2 返回 Json格式
最近在学习ASP.NET的Web API,刚刚开始以为会有些复杂,结果却非常简单. 学习的地址:http://www.asp.net/web-api/overview/getting-started- ...
- ASP.NET Core中返回 json 数据首字母大小写问题
ASP.NET Core中返回 json 数据首字母大小写问题 在asp.net core中使用ajax请求动态绑定数据时遇到该问题 后台返回数据字段首字母为定义的大写,返回的数据没有问题 但是在前台 ...
- asp.net webapi 返回json结果的方法
第一种: public static void Register(HttpConfiguration config) { //1.将默认的xml格式化程序清除 GlobalConfiguration. ...
- asp.net 重写OnException返回json或跳转新页面
protected override void OnException(ExceptionContext filterContext) { // 此处进行异常记录,可以记录到数据库或文本,也可以使用其 ...
随机推荐
- 简单的分页sql
select top 5 * from books where id not in(select top (5*(5-1)) id from Books order by id) order by i ...
- 实现gabor filter的滤波
实现gabor filter的滤波 图像纹理对于航空遥感图片.织物图案.复杂自然风景和动植物都适合.这里我采用遥感图片.织物图案和钢铁表面来做,并和canny图片进行一定的对比. ...
- python中string.casefold和string.lower区别
string.casefold和string.lower 区别 python 3.3 引入了string.casefold 方法,其效果和 string.lower 非常类似,都可以把字符串变成小写, ...
- noi 8465 马走日
8465:马走日 查看 提交 统计 提问 总时间限制: 1000ms 内存限制: 1024kB 描述 马在中国象棋以日字形规则移动. 请编写一段程序,给定n*m大小的棋盘,以及马的初始位置(x,y ...
- linux 强大的编辑器之vi
vi编辑器是一个处理ASCII数据的文本工具.大多数linux发行版都已经默认安装了vi编辑器.vi是visual interface的缩写vim是 visual interface improved ...
- sql 邮件发送测试情况
sql 邮件发送测试情况 select * from msdb.dbo.sysmail_allitems select * from msdb.dbo.sysmail_event_log
- dubbo源码之四——服务发布二
dubbo版本:2.5.4 2. 服务提供者暴露一个服务的详细过程 上图是服务提供者暴露服务的主过程: 首先ServiceConfig类拿到对外提供服务的实际类ref(如:HelloWorldImpl ...
- char、unsigned char、BYTE
首先uchar就是BYTE:Typedef unsigned char BYTE: char:就是signed char,是一个字节,8个位.第8位是符号位,所以可以表示-128~127共256个符号 ...
- CAShapeLayer 与贝塞尔曲线
一 CAShapeLayer 简介 1,CAShapeLayer继承至CALayer,可以使用CALayer的所有属性 2,CAShapeLayer需要与贝塞尔曲线配合使用才有意义:单独使用毫无意义 ...
- UVALive 5075 Intersection of Two Prisms(柱体体积交)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_ ...