解析来自经典 asp 服务器的 JSON 数据? [英] Parsing JSON data from classic asp server?

查看:79
本文介绍了解析来自经典 asp 服务器的 JSON 数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在这里看了几个问题/答案后,我没有看到我认为我需要什么.我有一个页面通过 ajax 发布到 asp 服务器页面.返回的 json 字符串显示在 Firefox 的控制台中.我可以看到进入asp页面的帖子数据,我可以看到响应是

After looking at several questions/answers here, I'm not seeing what I think I need. I have a page posting to an asp server page via ajax. The returning json string is showing up in the console on Firefox. I can see the post data going to the asp page, I can see the response which is

{ "firstname": "Christopher","lastname": "Romero","email": "cromero@marketscout.com","adminlvl": "00","message": "感谢您登录!"}

{ "firstname": "Christopher","lastname": "Romero","email": "cromero@marketscout.com","adminlvl": "00","message": "Thanks for logging in!" }

我还可以在 Console --> ALL --> JSON 的 JSON 选项卡中看到上述字符串的值.控制台内没有报告错误.这是我的 javascript:

I can also see the values of the string above in the JSON tab in Console --> ALL --> JSON. There are no errors being reported inside the console. Here is my javascript:

$('#loginsub').click(function() { 
$.ajax({
        url: "logincheck.asp",
        type: "POST",
        data: $('#loginform').serialize(),
        dataType: "json",
        success: function(data) {
            console.log(data);
            //alert(data.firstname + ' ' + data.lastname);  
            //alert(data[0].firstname + ' ' + data[0].lastname);    
            $.trim(data);
            var json = $.parseJSON(data);
            alert(json.firstname);
        }
});

    });

这是在 logincheck.asp 上的服务器上运行的 asp:

Here is the asp that is running on the server on logincheck.asp:

set cmd = Server.CreateObject("ADODB.Command")
with cmd
    .ActiveConnection = cnnopen
    .CommandText = storedproc
    .CommandType = adCmdStoredProc

    dim intCount,intItem
    for each item in odcformdata

        select case vartype(odcformdata(item)) 'this is searching for the correct data type to put into the parameter [type] argument below. (integers, currency, dates, & strings)
            case 2 : .Parameters.Append .CreateParameter("@"&cstr(item),adInteger,adParamInput,len(odcformdata(item)),odcformdata(item)) 
            case 6 : .Parameters.Append .CreateParameter("@"&cstr(item),adCurrency,adParamInput,len(odcformdata(item)),odcformdata(item))
            case 7 : .Parameters.Append .CreateParameter("@"&cstr(item),adDate,adParamInput,len(odcformdata(item)),odcformdata(item))
            case 8 : .Parameters.Append .CreateParameter("@"&cstr(item),adVarChar,adParamInput,len(odcformdata(item)),odcformdata(item))
        end select
    next

end with

set rs = cmd.execute
    'do stuff with returned results from select or leave blank if insert/delete/etc stored procedure

    if rs.EOF = false then
        'Build json array based on fields returned from stored proc.
        dim arrJSON
        arrJSON = "{ "
        while not rs.EOF
            for each fields in rs.Fields
                arrJSON = arrJSON & """" & fields.name & """: """ & fields & ""","
            next
            rs.movenext
        wend
        arrJSON = arrJSON & """message"": ""Thanks for logging in!"","
        arrJSON = left(arrJSON, len(arrJSON)-1) & " }"
        response.write arrJSON
    end if

set rs = nothing
set cmd = nothing

odcformdata.removeall

javascript 中的 alerts() 没有返回我期望的值,当我期望打印出 JSON 数组/字符串时,我得到了 [object Object] 返回的警报.

The alerts() in the javascript are not returning values that I would expect, I'm getting [object Object] returning on the alert when I'm expecting the JSON array/string to get printed out.

有人给我一些建议吗?我是一个 jquery 新手,并且越来越好,但这让我很紧张!

Anyone with some advice for me? I'm a jquery rookie and getting better, but this is getting on my nerves!

推荐答案

你的第一个 console.log(data) 显示了什么?

What does your first console.log(data) show?

这对我有用:http://jsfiddle.net/2tvCf/

这篇关于解析来自经典 asp 服务器的 JSON 数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆