Carlos Mendieta
Carlos Mendieta

Reputation: 872

Invalid Character using json

I read a record from my sql server database into a datatable. From there I use newtonsoft's JSON for .NET and run it through

JsonConvert.SerializeObject(DataTable)

I get the following json string output:

[{"Type":"Support-D325","condition":"#2 support beam 1/2\" crack","Length":245.0,"Date_Found":"2018-08-09T08:01:51"}]

and store it in a session variable. Later, client-side I use

data = $.parseJSON('<%= Session("JSONDataTable") %>');

but get the INVALID CHARACTER error. Now I'm guessing its the #2 support beam 1/2\" crack that's doing causing the problem. Is there some JSON command that can fix this so I don't throw the error?

Thank you

Upvotes: 0

Views: 572

Answers (2)

Mohsin Mehmood
Mohsin Mehmood

Reputation: 4236

You don't need JSON.parse I believe. Just do it like this:

data = <%= Session("JSONDataTable") %>;

Upvotes: 1

Hugo Roca
Hugo Roca

Reputation: 11

Your problem is in the "\" character, I recommend that you do the transform to string and replace it, then show it again:

data = $.parseJSON('<%= Session("JSONDataTable") %>');

Upvotes: 1

Related Questions