小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

json學(xué)習(xí)筆記

 昵稱10504424 2012-08-03

Json介紹:

  JSON(JavaScript Object Notation) 是一種輕量級的數(shù)據(jù)交換格式。易于人閱讀和編寫。
      json 官方網(wǎng)站 http://www./
      json.net 下載地址 http://json./releases/view/37810

Demo:

  

描述:

  點擊獲取按鈕后,將請求頁面,獲取json數(shù)據(jù),填充到表格

html代碼:

  

復(fù)制代碼
代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www./1999/xhtml">
<head runat="server">
<title></title>

<script type="text/jscript" src="../jquery/jquery-1.4.2.min.js"></script>

<script language="javascript" type="text/javascript">
$(
function() {
$(
"#Button1").click(function() {
$.get(
"json1.aspx?m=m", null, function(callbackmsg) {
var product = eval(callbackmsg);
ShowProduct(product)
})
});
})
function ShowProduct(callbackmsg) {
var row='';
for (var u in callbackmsg) {
var len = callbackmsg[u].length;
row
+= '<tr>';
row
+= '<td>' + callbackmsg[u].Name + '</td>';
row
+= '<td>' + callbackmsg[u].Price + '</a></td>';
row
+= '<td>' + callbackmsg[u].Size + '</td>';
row
+= '</tr>';
}
$(
"#body").html(row);
}
</script>

</head>
<body>
<form id="form1" runat="server">
<div>
<input id="Button1" type="button" value="獲取" />
</div>
<table>
<thead>
<tr>
<th>
名稱
</th>
<th>
價格
</th>
<th>
大小
</th>
</tr>
</thead>
<tbody id="body">
</tbody>
</table>
</form>
</body>
</html>
復(fù)制代碼

后臺代碼:

復(fù)制代碼
代碼
public partial class json1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (HttpContext.Current.Request.QueryString["m"] != null)
{
List
<Product> Products = new List<Product>();
Products.Add(
new Product() { Name = "筆記本", Price = "4.2", Size = "30x50" });
Products.Add(
new Product() { Name = "尺子", Price = "1.2", Size = "30x50" });
Products.Add(
new Product() { Name = "", Price = "36", Size = "30x50" });
Products.Add(
new Product() { Name = "鋼筆", Price = "6.0", Size = "30x50" });
Products.Add(
new Product() { Name = "鉛筆", Price = "2.2", Size = "30x50" });
string json = JsonConvert.SerializeObject(Products);
Response.Write(json);
Response.End();
}
}
}
public class Product
{
public string Name { get; set; }
public string Size { get; set; }
public string Price { get; set; }
}
復(fù)制代碼

知識點:

  1.json官方提供了用于.net操作的dll類庫,JsonConvert.SerializeObject將.net對象序列化為json。

  2.Javascript讀取json對象var product = eval(callbackmsg)。

  3.Javascript讀取json值callbackmsg[u].Name。

分類: 其它
標(biāo)簽: jquery, json

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多