json解析list

yang56800058 2012-05-02 11:45:24
<table width="100%" border="0" id="table1" cellpadding="10" cellspacing="10" align="center"
style="margin-top: 8px">
<tr>
<td colspan="4">
<span style="font-size: 25px;">酒店招聘信息 </span>
</td>
</tr>
<tr>
<th>
酒店编号
</th>
<th>
酒店名称
</th>
<th>
开始/结束时间
</th>
<th>
总/已招
</th>
<th>
选择
</th>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr align="center">
<td>
<span class="name_sp">
<asp:Label ID="Label1" runat="server" Text='<%# Eval("Grog_id") %>'></asp:Label>
</span>
</td>
<td>
<span class="name_sp">
<asp:Label ID="Label6" runat="server" Text='<%# Eval("grogname") %>'></asp:Label>
</span>
</td>
<td>
<span class="time_sp">
<asp:Label ID="Label2" runat="server" Text='<%# Eval("grogstart") %>'></asp:Label>|
<asp:Label ID="Label3" runat="server" Text='<%# Eval("grogend") %>'></asp:Label>
</span>
</td>
<td>
<span class="num_sp">
<asp:Label ID="Label4" runat="server" Text='<%# Eval("grogsum") %>'></asp:Label>/
<asp:Label ID="Label5" runat="server" Text='<%# Eval("grognum") %>'></asp:Label>
</span>
</td>
<td>
<span class="check_sp">
<asp:CheckBox ID="CheckBox1" runat="server" Checked="true" /> 是否招聘</span>
</span>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<tr align="right">
<td colspan="4">
<p style="width: 100%;" id="id1">
 </p>
</td>
</tr>
<tr align="right">
<td colspan="4">
<asp:ImageButton ID="ImageButton1" ImageUrl="images/submit_btn.png" runat="server"
OnClick="ImageButton1_Click" />
</td>
</tr>
</table>
...全文
593 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yang56800058 2012-05-07
  • 打赏
  • 举报
回复
还是没懂...能加你QQ帮我下嘛? 我的QQ475089730 非常感谢
xiage 2012-05-03
  • 打赏
  • 举报
回复
//如果后台的数据是list,那么items就是"数组",里面的元素就是json对象.
获取对象:items[0].id;
xiage 2012-05-03
  • 打赏
  • 举报
回复
sorry,写错了,
//如果后台的数据是list,那么items就是"数组",里面的元素就是json对象.
比如 items[0].id;
xiage 2012-05-03
  • 打赏
  • 举报
回复

List<Object> items = new List<Object>();
System.Web.Script.Serialization.JavaScriptSerializer jss = new System.Web.Script.Serialization.JavaScriptSerializer();
jsonString = jss.Serialize(items);
return jsonString;

楼主可以参照上面的代码,讲后台方法返回string,而不是List,
然后可以在页面上用下面的方法来解析成json,


$.ajax({
type: "POST",
url: url,
data: "{code:'" + code + "'}",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var items = $.parseJSON(data.d);//To json
//如果后台的数据是list,那么items就是数字,里面的元素就是json对象.
}
});


yang56800058 2012-05-02
  • 打赏
  • 举报
回复
[WebMethod]
public static List<Model_grog> select(string time, string grogid)//返回的LIST 键值对 list里面都是实体
{
jiami jia = new jiami();
Bll_users bll = new Bll_users();
int grog_id = a.normal.toInt(jia.Code(grogid.ToString()));
List<Model_grog> list = bll.p_select_time(time, grog_id);
return list;
}
yang56800058 2012-05-02
  • 打赏
  • 举报
回复
<script type="text/javascript">
var oo = {
_year: 2012,
_month: 4,
_date: 27,

_year2: 2012,
_month2: 4,
_date2: 27,

show: function (i) {
if (i == -1) {
this._month -= 1;
if (this._month < 10) {
this._month = "0" + this._month;
}
if (this._month == 0) {
this._year -= 1;
this._month = 12;
}
}
if (i == 1) {
if ((this._month.toString().substring(0, 1)) == 0) {
this._month = parseInt(this._month.substring(1, 2));
}
this._month += 1;
if (this._month < 10) {
this._month = "0" + this._month;
}
if (this._date)
if (this._month == 13) {
this._year += 1;
this._month = 1;
}
if (this._month == 1) {
this._month = "01";
}
}
this.showlist()
},
getdays: function (months) {
var month = 0;
if (months >= 10) {
month = months
}
else {
month = months.substring(1, 2);
}
if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) {
return 31;
}
else if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
else {
return 28;
}
},
showlist: function () {
var week_start = new Date(this._year + '/' + this._month + '/1').getDay();
var Month_maxDays = this.getdays(this._month);
var dd = 0;
var html = "<div class='calendar_top'><dl><dt ><a onclick='oo.show(-1)' class='img_btn'><img src='../images/prv.png'/></a></dt><dt class='calendar_topmiddle'>" + this._year + '-' + this._month + "</dt><dt><a onclick='oo.show(1)' class='img_btn'><img src='../images/next.png'/></a></dt></dl></div><div class='clear_left'></div>";
html += "<table class='calendar_content' cellpadding='0' cellspacing='0'>";

for (var i = 1; i <= 6; i++) {
html += "<tr>";
for (var j = 1; j <= 7; j++) {

if (dd == 0 && j == week_start + 1) {
dd = 1;
}
if (dd == 0 || dd > Month_maxDays) {
html += '<td>  </td>';
}
else if (dd == this._date2 && this._month == (this._month2 + 1) && this._year == this._year2) {
if (dd < 10) {
html += '<td class="dddd" id="thatDay" date="' + this._year + '-' + this._month + '-0' + dd + '">' + dd + '</td>';
}
else {
html += '<td class="dddd" id="thatDay" date="' + this._year + '-' + this._month + '-' + dd + '">' + dd + '</td>';
}
dd++;
}
else {
if (dd < 10) {
if (dd == 1) {
html += '<td style="background" id="onclickDay' + dd + '" onclick="buttonMouseClick(this.id)" date="' + this._year + '-' + this._month + '-0' + dd + '">' + dd + '</td>';
}
else {
html += '<td class="dddd" id="onclickDay' + dd + '" onclick="buttonMouseClick(this.id)" date="' + this._year + '-' + this._month + '-0' + dd + '">' + dd + '</td>';
}
}
else
html += '<td class="dddd" id="onclickDay' + dd + '" onclick="buttonMouseClick(this.id)" date="' + this._year + '-' + this._month + '-' + dd + '">' + dd + '</td>';

dd++;
}
}
html += "</tr>";
}
html += "</table>";

$('#listbox').html(html);


$('.dddd').click(function () {
var date = $(this).attr('date');
//异步查询数据
//window.location.href = 'grog_tow.aspx?date=' + date + "&" + parastr;
//window.location("gorg.aspx/select?time=" + date + "&grogid=" + parastr);
$.ajax({
type: "POST",
contentType: "application/json",
url: "gorg.aspx/select",
data: "{time:'" + date + "',grogid:'" + parastr + "'}",
dataType: 'json',
success: function (list) {
$(list.d).each(function () {
//alert(list.id, function (i, item) {
//alert(list.Id);
//$('#id1').append(this.toString() + " ");
//alert(list.d.join(" | ").grogid);
});

// jQuery.each(list.time, function (i, item) {
// alert(item.time + "," + item.grogid);
// });
}
});
});
}
}
var preButtonID = "null";
function buttonMouseClick(buttonID) {
if (preButtonID != "null") {
alert(preButtonID);
document.getElementById(preButtonID).style.background = "url(../images/calendar_static01.png) no-repeat";
}
document.getElementById(buttonID).style.background = "url(../images/calendar_static03.png) no-repeat";
document.getElementById(buttonID).style.width = "38px";
document.getElementById(buttonID).style.height = "30px";
preButtonID = buttonID;
}
//改变颜色

$.post("gorg.aspx/select_time_color", { grogid: "" + parastr + "", time: "" + date + "" }, resultss);
function resultss(e) {
if (e == 0) {

alert(e);
// document.getElementById(buttonID).style.background-color = "red";
// document.getElementById(buttonID).style.width = "38px";
// document.getElementById(buttonID).style.height = "30px";
}
else if (e == 1) {
// document.getElementById(buttonID).style.background-color = "green";
// document.getElementById(buttonID).style.width = "38px";
// document.getElementById(buttonID).style.height = "30px";
}
}
var myDate = new Date();
oo._date2 = myDate.getDate();
oo._month2 = myDate.getMonth();
oo._year2 = myDate.getFullYear();

var str = window.location.href;
pos = str.indexOf("=");
var parastr = str.substring(pos + 1);
if (parastr.indexOf("&") <= 0) {
oo._date = myDate.getDate();
oo._month = myDate.getMonth() + 1;
if (oo._month < 10) {
oo._month = "0" + oo._month;
}
oo._year = myDate.getFullYear();
}
else {
var ss = parastr.indexOf("&");
var date = parastr.substring(5, ss);
oo._date = date.substring(8, 10);
oo._month = date.substring(5, 7);
oo._year = date.substring(0, 4);
}
if (parastr.indexOf("&") >= 0) {
var ss = parastr.indexOf("&");
parastr = parastr.substring(ss + 1);
}
oo.showlist();
</script>

52,782

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧