jquery解析json

 <section id="agentoverseas" class="bgnone pb1">
		 	  	  	   @*<h3 class="ptopa5">Argentina / Buenos Aires</h3>
		 	  	  	   <p class="ptopa5 font12">
		 	  	  	   	OVERSEAS ARGENTINA S.A. 
		 	  	  	   	<br />
		 	  	  	   	SUIPACHA 268 5TH FLOOR (C1008AAF) BUENOS AIRES REPUBLICA ARGENTINA CUIT: 30-68082073-9
		 	  	  	   </p>
		 	  	  	   <div class="under font12" style="border-top:1px #CCC solid;border-spacing: 0;">
 	  	   	     	 		 <span class="leftunder">URL</span>
 	  	   	     	 		 <span class="rightunder pleft9">-</span>
 	  	   	     	 	</div>
 	  	   	     	 	
 	  	   	     	 	<div class="under font12">
 	  	   	     	 		 <span class="leftunder">Tel</span>
 	  	   	     	 		 <span class="rightunder pleft9">54 11 4320-9700</span>
 	  	   	     	 	</div>
 	  	   	     	 	<div class="under font12">
 	  	   	     	 		 <span class="leftunder">Fax</span>
 	  	   	     	 		 <span class="rightunder pleft9">54 11 4320-9710</span>
 	  	   	     	 	</div>
 	  	   	     	 	<div class="under font12">
 	  	   	     	 		 <span class="leftunder">E-mail</span>
 	  	   	     	 		 <span class="rightunder pleft9"></span>
 	  	   	     	 	</div>*@
 	  	   	     	 	
 	  	   	     	 	
		 	  	  </section>

上面是要插入的地方

两个console.log()

 function appendHtml() {
	        $.post("@Url.Action("LoadOverseas", "NetworkAgent")", { country: $("#country").combobox("getValue"), city: $("#city").combobox("getValue") }, function (data) {
	       
	            console.log(data)
	        var html = "";
	        data = $.parseJSON(data);
	            console.log(data)
	            $.each(data, function (index, info) {
	                var detail = $.parseJSON(info["detail"]);
	                $.each(detail, function (detailIndex, detailinfo) {
	                    html +=" <h3 class=\"ptopa5\"> "+ info["country"] +"/"+ detailinfo["city"] +"</h3>"
	                    html +="<p class=\"ptopa5 font12\">"
	                    html += 	detailinfo["branch"] 
	                    html += "	<br />"
	                    html +=	detailinfo["address"]
	                    html +=	"</p>"
	                    html +=" <div class=\"under font12\" style=\"border-top:1px #CCC solid;border-spacing: 0;\">"
	                    html +=" <span class=\"leftunder\">URL</span>"
	                    html +=" <span class=\"rightunder pleft9\">"+ detailinfo["url"] +"</span>"
	                    var contact = $.parseJSON(detailinfo["contact"]);
	                    $.each(contact, function (contactIndex, contactinfo) {
	                        html +="</div>"	  	   	     	 	
	                        html +="<div class=\"under font12\">"
	                        html +=" <span class=\"leftunder\">Tel</span>"
	                        html +=" <span class=\"rightunder pleft9\">"+ contactinfo["tel"] +"</span>"
	                        html +="	</div>"
	                        html +="<div class=\"under font12\">"
	                        html +=" <span class=\"leftunder\">Fax</span>"
	                        html +=" <span class=\"rightunder pleft9\">"+ contactinfo["fax"] + "</span>"
	                        html +="	</div>"
	                        html +="<div class=\"under font12\">"
	                        html +=" <span class=\"leftunder\">E-mail</span>"
	                        html +=" <span class=\"rightunder pleft9\">"+ contactinfo["email"] + "</span>"
	                    });
	                    html +="</div>"
	                });
	            });
	            $("#agentoverseas").html(html);
	        //$.each(obj, function (index, info) {
	        //    html += "<h3>" + info["country"] + "</h3>";
	        //    var detail = $.parseJSON(info["detail"]);
	        //    $.each(detail, function (detailIndex, detailinfo) {
	        //        html += "     <div class=\"context\">";
	        //        html += "         <div class=\"contexthead\">";
	        //        html += "             <span class=\"city\">" + detailinfo["city"] + "</span>";
	        //        html += "             <span class=\"branch\">" + detailinfo["branch"] + "</span>";
	        //        html += "         </div>";
	        //        html += "         <div class=\"line\"></div>";
	        //        html += "         <p class=\"address\">" + detailinfo["address"] + "</p>";
	        //        html += "         <p class=\"url\">URL:&nbsp;<span>" + detailinfo["url"] + "</span></p>";
	        //        var contact = $.parseJSON(detailinfo["contact"]);
	        //        $.each(contact, function (contactIndex, contactinfo) {
	        //            html += "         <p class=\"tel\">TEL:&nbsp;<span>" + contactinfo["tel"] + "</span></p>";
	        //            html += "         <p class=\"fax\">FAX:&nbsp;<span>" + contactinfo["fax"] + "</span></p>";
	        //            html += "         <p class=\"email\">EMAIL:&nbsp;<span>" + contactinfo["email"] + "</span></p>";
	        //        });
	        //        html += "     </div>";
	        //    });
	        //});
	        //    $("#agentoverseas").html(html);

	        });
	    }

解析  好多层

<select class="easyui-combobox Sdselect" id="country"                                               style="width: 100%; height: 25px;">


function countryConst() {
	        $("#country").combobox({
	            url: "@Url.Action("GetConstCountry", "Agency")",
                valueField: "id",
                textField: "text",
                onLoadSuccess: function () {
                    $(this).combobox("setValue", "0");
                },
                onChange: function (newValue, oldValue) {
                    cityConst();
                }
            });
        }

        function cityConst() {
            $("#city").combobox({
                url: "@Url.Action("GetConstCity", "Agency")" + "?Country=" + $("#country").combobox("getValue"),
            valueField: "id",
            textField: "text",
            onLoadSuccess: function () {
                $(this).combobox("setValue", "0");
            }
        });
    }

国家和city  下拉框

 public string LoadOverseas()
        {
            string strCountry = CommHelper.GetString(Request["country"]);
            string strCity = CommHelper.GetString(Request["city"]);

            DataTable dtRet = new DataTable();
            dtRet.Columns.Add("country");
            dtRet.Columns.Add("detail");
            string strSQL = "select MTBranch.BranchNo,MTBranch.Country,MTBranch.Company ,MTBranch.Address,MTBranch.URL,MTBranchPort.PortName  from MTBranchPort inner join MTBranch on MTBranch.BranchNo = MTBranchPort.BranchNo and MTBranch.BranchType =3";

            if (strCountry != "0")
                strSQL = strSQL + " And MTBranch.Country='" + strCountry + "'";

            if (strCity != "0")
                strSQL = strSQL + " And MTBranchPort.PortName='" + strCity + "'";

            DataTable dt = SQLHelper.ExcuteGetDataTable(strSQL);
            if (dt != null && dt.Rows.Count > 0)
            {
                var country = (from q in dt.AsEnumerable() select q.Field<string>("Country")).Distinct().OrderBy(x => x);

                foreach (var x in country.ToList())
                {
                    DataTable dtDetail = new DataTable();
                    dtDetail.Columns.Add("city");
                    dtDetail.Columns.Add("branch");
                    dtDetail.Columns.Add("address");
                    dtDetail.Columns.Add("url");
                    dtDetail.Columns.Add("contact");

                    var detail = from q in dt.AsEnumerable() where q.Field<string>("Country") == x orderby q.Field<string>("PortName") select q;
                    foreach (var d in detail.ToList())
                    {
                        DataTable dtContact = new DataTable();
                        dtContact.Columns.Add("tel");
                        dtContact.Columns.Add("fax");
                        dtContact.Columns.Add("email");
                        string strSQLcontact = "select tel,fax,email from MTBranchContact where BranchNo='" + d.Field<string>("BranchNo") + "'";
                        dtContact.Clear();
                        dtContact.Merge(SQLHelper.ExcuteGetDataTable(strSQLcontact));
                        dtDetail.Rows.Add(d.Field<string>("PortName"), d.Field<string>("Company"), d.Field<string>("Address"), d.Field<string>("URL"), JsonConvert.SerializeObject(dtContact));
                    }
                    dtRet.Rows.Add(x, JsonConvert.SerializeObject(dtDetail));
                }
            }

            return JsonConvert.SerializeObject(dtRet);
        }

控制器代码

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值