rcdmk / aspJSON

A fast classic ASP JSON parser and encoder for easy JSON manipulation to work with the new JavaScript MV* libraries and frameworks.
MIT License
204 stars 89 forks source link

Using JSON.Add inside a For Each #23

Closed JohEngstrom closed 8 years ago

JohEngstrom commented 8 years ago

I'm trying to build a JSON feed from a database recordset but I'm running into an issue where I get an Internal Server Error which makes it really hard to debug.

Maybe you can see where I'm going wrong?

The code works fine before I add in the JSON class code.

This is my code I'm playing around with:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<%
    Response.CodePage = 65001
    Response.CharSet = "utf-8"
%>
<!--#include virtual="/connection-strings/connection-string.asp" -->
<!--#include file="jsonObject.class.asp" -->
<%
    Dim Recordset1
    Dim Recordset1_cmd
    Dim Recordset1_numRows
    set JSON = New JSONobject

    Set Recordset1_cmd = Server.CreateObject ("ADODB.Command")
    Recordset1_cmd.ActiveConnection = MM_pk_hnCOM_ADO_STRING
    Recordset1_cmd.CommandText = "SELECT * FROM dbo.table WHERE ID IN ('1541816', '1541821')"
    Recordset1_cmd.Prepared = true

    Set Recordset1 = Recordset1_cmd.Execute
    Recordset1_numRows = 0

    While Not Recordset1.EOF
        For each item in Recordset1.Fields
            JSON.Add item.Name, Recordset1(item.Name)
        Next
        Recordset1.MoveNext
    Wend

    Dim jsonString
    jsonString = JSON.Serialize()

    JSON.Write()
%>

Thank you!

rcdmk commented 8 years ago

Hi. Can you post the error message? I need to know if you are running this with the IIS debug server enabled too.

I have an open issue about an error that is thrown only when server debug mode is enabled.

rcdmk commented 8 years ago

Also, have you seen the methods .LoadRecordset(byref rs) and .LoadFirstRecord(byref rs)?

Take a look at the README file if you have any doubt about them: https://github.com/rcdmk/aspJSON

rcdmk commented 8 years ago

I'll close this. If you still have any issues with this, please reopen it.

Thx