Implementing c# to serialize data into JSON
and transmitting it to JavaScript using the code below:
string serializedDS = JsonConvert.SerializeObject(ftpd);
ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "text", string.Format("Func('{0}');", serializedDS), true);
The result of
JsonConvert.SerializeObject(ftpd)
is {"FTPUserName":"XKK\\xpuser1","FTPPassword":"xpr@fr@12","FTPServerAddress":"255.255.255.0","FTPPath":"In/Files"}
This is my JavaScript function:
function Func(serializedDS) {
var result = JSON.parse(serializedDS);
if (result != null)
{
var a = result["FTPUserName"];
var b = result["FTPPassword"];
var c = result["FTPServerAddress"];
var d = result["FTPPath"];
}
}
The data received as an argument in the function is
serializedDS = "{"FTPUserName":"XKK\xpuser1","FTPPassword":"xpr@fr@12","FTPServerAddress":"255.255.255.0","FTPPath":"In/Files"}"
However, at the line
var result = JSON.parse(serializedDS);
, I encounter this error Uncaught SyntaxError: Unexpected token x in JSON at position 20
at JSON.parse (<anonymous>)
I would appreciate any assistance with this issue!