读取JSON数据返回的jQuery数据、JSON、jQuery

2023-09-10 19:40:16 作者:枕边旧宠

我用下面的code得到一些JSON格式的数据:

I'm using the following code to get some json formatted data:

$.ajax({
            type: "GET",
            url: "MyService.svc/GetSomeData",
            dataType: "text",
            success: function (data, textStatus) {

                alert("Test: " + data.toString());
            },
            error: function (xhr, textStatus, errorThrown) {
                alert("Error: " + (errorThrown ? errorThrown : xhr.status));
            }
        });

数据成功地返回到该电话,它看起来是这样的:

Data is successfully returned to this call, and it looks like this:

{"d":"test data"}

我的猜测是,我可以按如下方法访问数据:

My guess was that I could access the data as follows:

var myData = data["d"];

不过,这似乎总是返回未定义。我在想什么来获取数据的单一字符串测试数据?

However this seems to always return "undefined". What am I missing to get the single string of data "test data"?

推荐答案

如果您尝试会发生什么 data.d

what happens if you try data.d?