2012-05-10 57 views
0

ApiController爲什麼返回的JSON包含一個 '對象' 標籤

public List<FileModel> Get(string foldername) 

在客戶端,

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); 
     } 
    }); 

console.log顯示檢索msg是:

[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...}] 

代替的格式爲

[{Extension=".pdf",...}, {...}, {...}] 

爲什麼我會得到所有這些額外的Object?我該如何刪除它們?

回答

1

jQuery自動將JSON解析爲JavaScript對象,所以不用擔心。這只是如何console.log()打印對象。

+0

謝謝。當我的代碼無法工作時,我懷疑是錯誤的。 – Blaise

相關問題