Json 字符串如下所示:-{ d: {"lstname": { "Fname":"test", "LName":"data" }, "lstAddress": { "address1":"abc", "address2":"def", "pincode":"0", "Area":"Bhandup" } } }代码<body> <form id="form1" runat="server"> <%--<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />--%> <input type="button" name="btn1" id="Getdata" value="Getdata" /> <div id="name"> </div> <div id="Addess"> </div> </form></body>lstname 数据应显示在名称 div 中,lstaddress 数据应显示在地址 div 中
1 回答
慕森王
TA贡献1777条经验 获得超3个赞
我已经修复了一些JSON - 我已经在'd:'属性中添加了“”。所以这里的工作版本:在JSFiddle中
var str = `{
"d": {"lstname":
{
"Fname":"test",
"LName":"data"
},
"lstAddress":
{
"address1":"abc",
"address2":"def",
"pincode":"0",
"Area":"Bhandup"
}
}
}`;
var obj = JSON.parse(str);
$(function(){
$('#name').text(obj.d.lstname.Fname + ' ' + obj.d.lstname.LName)
$('#Addess').text(obj.d.lstAddress.address1 + ' ' + obj.d.lstAddress.address2 + ' ' + obj.d.lstAddress.pincode + ' ' + obj.d.lstAddress.Area)
});
- 1 回答
- 0 关注
- 72 浏览
添加回答
举报
0/150
提交
取消