来自mvc控制器的jquery解析模型json

时间:2016-08-31 11:39:10

标签: jquery json

我在ASP.net上编写了控制器,它返回了我的自定义类对象列表。我收到了这个json,但是当我尝试foreach它时,它告诉我,那个元素未定义。我该如何解决?

 $("#Selector").change(function () {

    $.ajax({
        type: "GET",
        url: "/test",
        data: "",
        async: false,
        success: function (response) {
            console.log(response);// show -> [Object {id="1", title="title1", Name="name1"},Object {id="2", title="title2", Name="name2"},Object {id="3", title="title3", Name="name3"}]


            $.each(response, function (data) {
                console.log("======================");
                console.log("Id:" + data.id); //show data.id is undefined
                console.log("Title:" + data.title);//show data.title is undefined
                console.log("Automated Test Name:" + data.automatedTestName);//show data.automatedTestName is undefined

            });

        },
        dataType: "json"

    })
});

0 个答案:

没有答案