【发布时间】:2021-03-24 22:03:46
【问题描述】:
桌子是空的。没有数据。
public JsonResult GetData(){
Uri url=new Uri("https://rallycoding.herokuapp.com/api/music_albums");
WebClient client=new WebClient();
client.Encoding=System.Text.Encoding.UTF8;
string json=client.DownloadString(url);
return Json(json);
}
<table id="example" class="table table-bordered table-striped table-sm">
<thead>
<tr>
<th>title</th>
<th>artist</th>
<th>url</th>
</tr>
</thead>
</table>
<script>
$(document).ready(function(){
$.ajax({
datatype:"json",
url:"/Home/GetData",
succes:function(data){
var obj=Json.parse(data);
}
})
var table=$('#example').DataTable({
'data':obj,
'paging':true,
'searching':true,
'ordering':true
})
})
</script>
我可以将 JSON 数据解析到列表中并使用 viewbag 将其写入表中,但我必须将其 JSON 到数据表中。
你能帮帮我吗?
【问题讨论】: