日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

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

 昵稱(chēng)10504424 2012-08-03

Json介紹:

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

Demo:

  

描述:

  點(diǎn)擊獲取按鈕后,將請(qǐng)求頁(yè)面,獲取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>
名稱(chēng)
</th>
<th>
價(jià)格
</th>
<th>
大小
</th>
</tr>
</thead>
<tbody id="body">
</tbody>
</table>
</form>
</body>
</html>
復(fù)制代碼

后臺(tái)代碼:

復(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 = "書(shū)", 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ù)制代碼

知識(shí)點(diǎn):

  1.json官方提供了用于.net操作的dll類(lèi)庫(kù),JsonConvert.SerializeObject將.net對(duì)象序列化為json。

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

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

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

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

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶(hù) 評(píng)論公約

    類(lèi)似文章 更多