A
A
artshelom2019-02-09 08:57:23
ASP.NET
artshelom, 2019-02-09 08:57:23

When I try to make an object from a JSon object, it writes an error of an unknown character &, how to fix it?

I'm trying to convert Object to json chrome writes an error:
Uncaught SyntaxError: Unexpected token &
Code:

var tr = @Newtonsoft.Json.JsonConvert.SerializeObject(traingObj);
  start(@tr);

How to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny, 2019-02-12
Maltsev @maltsever

Hey! Perhaps the option is suitable when we serialize html characters into an escape sequence:

var settings = new JsonSerializerSettings
{
    StringEscapeHandling = StringEscapeHandling.EscapeHtml
};
var tr = @Newtonsoft.Json.JsonConvert.SerializeObject(traingObj, settings);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question