My ApiController is
public List<FileModel> Get(string foldername)
on the client side,
function ListFiles(folder) {
$.ajax({
url: "/api/Files",
data: "foldername=" + folder,
type: "GET",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
console.log("msg: ", msg);
$('#Container').setTemplateURL('/Templates/files.htm', null, { filter_data: false });
$('#Container').processTemplate(msg);
}
});
The console.log shows the retrieved msg is:
[Object { Extension=".pdf", FileName="Microsoft.Press.MCTS.Se...ing.Kit.Exam.70-503.pdf", FilePath="C:\inetpub\Examples\Fil...ing.Kit.Exam.70-503.pdf", more...},
Object { Extension=".pdf", FileName="Microsoft.Press.MCTS.Se...ing.Kit.Exam.70-515.pdf", FilePath="C:\inetpub\Examples\Fil...ing.Kit.Exam.70-515.pdf", more...},
Object { Extension=".pdf", FileName="Microsoft.Press.MCTS.Se...xam.70.516.May.2011.pdf", FilePath="C:\inetpub\Examples\Fil...xam.70.516.May.2011.pdf", more...}]
instead of in the format of
[{Extension=".pdf",...}, {...}, {...}]
Why do I get all those extra Object? And how can I remove them?
jQuery is automatically parsing the JSON into JavaScript objects for you, so don’t worry about it. It’s just how
console.log()prints objects.