无法在控制台中打印多个对象? Json数据: -
String[] ext = "*.ext1|*.ext2".Split('|');
List<String> files = new List<String>();
foreach (String tmp in ext)
{
files.AddRange(Directory.GetFiles(dir, tmp, SearchOption.AllDirectories));
}
我也必须使用
将它附加到循环中的div上[{"id":101,"email":"xxxx@gmail.com","mn":"+0000000","ut":0,"gen":0,"cy":0,"cp":0},{"id":102,"email":"xxxxx@gmail.com","mn":"+00000","ut":0,"gen":0,"cy":0,"cp":0},{"id":103,"email":"xxxx@gmail.com","mn":"+000000","ut":0,"gen":0,"cy":0,"cp":0}
我用这个: -
$('div#datainfo').text(mn);
错误: -
[](null arrary)
答案 0 :(得分:1)
您可以使用此代码
$(document).ready(function(){
var data = [
{
"id":101,
"email":"xxxx@gmail.com",
"mn":"+0000000",
"ut":0,
"gen":0,
"cy":0,
"cp":0
},
{
"id":102,
"email":"xxxxx@gmail.com",
"mn":"+00000",
"ut":0,
"gen":0,
"cy":0,
"cp":0
},
{
"id":103,
"email":"xxxx@gmail.com",
"mn":"+000000",
"ut":0,
"gen":0,
"cy":0,
"cp":0
}
];
for(i = 0; i < data.length; i++){
alert(JSON.stringify(data[i]));
$('div#datainfo').append('<div class="alert alert-info" role="alert">'+
'<p>Mobile:- <b id="">'+ data[i].mn+'</b></p>'+
'<p>Name :- <b>'+ data[i].email+'</b> </p>'+
'</div>');
};
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div>
<div id='datainfo'>
</div>
</div>
&#13;
使用append
确保div
中的上一个文字仍然存在。