未终止的字符串错误将 JSON 对象从服务器移动到客户端 (VB.NET)

Unterminated String error moving JSON object from server to client (VB.NET)

我正在尝试使用 NewtonSoft.JSON for .NET 来序列化一个对象,以便我可以将该数据传递给客户端,我有以下 类 将数据存储在服务器端:

Public Class BankAccountPaymentProfile
    Public Property BankAccountProfileID As String
    Public Property AccountNumber As String
    Public Property AccountType As String
    Public Property RoutingNumber As String
    Public Property BankName As String
    Public Property NameOnAccount As String
    Public Property BillTo As New BillToProfile
End Class

Public Class BillToProfile
    Public Property billTofirstName As String = ""
    Public Property billTolastName As String = ""
    Public Property BillToaddress As String = ""
    Public Property billTocity As String = ""
    Public Property billTostate As String = ""
    Public Property billTozip As String = ""
    Public Property billTophoneNumber As String = ""
    Public Property billToemail As String = ""
End Class

在后面的代码中,我实例化了 类 并填充数据,然后用这行代码将其序列化:

Profiles = JsonConvert.SerializeObject(BankAccountProfile, Formatting.Indented)

在客户端,我有这个 jQuery 函数,我在(文档)中调用它。准备将数据发送到客户端:

    function GetProfileList() {
        $.ajax({
            type: "POST",
            contentType: "application/json",
            data: '{object:[<%=Profiles%>]}',
            url: "Subscription.aspx/MyProfiles",
            dataType: "json",
            success: function (data) {
                alert("Success");
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Failed");
                debugger;
            }
        });
    };

我在客户端浏览器中收到错误"Unterminated String",调试器中客户端显示的数据是:

'{object:[{
  "BankAccountProfileID": "1503460396",
  "AccountNumber": "XXXX7620",
  "AccountType": "0",
  "RoutingNumber": "XXXX0010",
  "BankName": "Bank Of AHoles",
  "NameOnAccount": "Firstname Lastname",
  "BillTo": {
    "billTofirstName": "",
    "billTolastName": "",
    "BillToaddress": "",
    "billTocity": "",
    "billTostate": "",
    "billTozip": "",
    "billTophoneNumber": "",
    "billToemail": ""
  }
}]}'

我想可能是因为我有一个对象嵌套在一个对象中,所以我删除了 BillTo 对象,同样的错误。数据显然正在到达客户端,但对于错误,我看不出字符串有什么问题。我错过了什么?

看来我做的事情很复杂,我需要做的就是将序列化的字符串返回给客户端,ajax调用是不必要的。

在(文件).ready:

// Creates an object of profiles contained in the JSON string
var = var Profiles = $(<%=Profiles%>);
var = accountprofileid = Profiles.accountprofileid;

...等...

完成....