【问题标题】:why returned json contains an 'object' tag为什么返回的 json 包含一个“对象”标签
【发布时间】:2012-05-11 04:53:21
【问题描述】:

我的ApiController

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?我怎样才能删除它们?

【问题讨论】:

    标签: jquery asp.net-web-api


    【解决方案1】:

    jQuery 会自动将 JSON 解析为 JavaScript 对象,所以不用担心。这就是console.log() 打印对象的方式。

    【讨论】:

    • 谢谢。当我的代码无法工作时,我似乎怀疑是错误的事情。
    猜你喜欢
    • 2019-10-29
    • 2013-05-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-11
    • 1970-01-01
    • 2018-12-29
    • 1970-01-01
    相关资源
    最近更新 更多