Json and exception System.ArgumentException: 'Escape sequence not recognized.. (48):

César Oliveira 1 Reputation point
2020-09-15T21:16:44.403+00:00

Hello People, Good Night,

The code above generate the Exception System.ArgumentException: 'Escape sequence not recognized. (48):

Dim resposta As String ="{"SUCCESS":0,"IDERRO":1,"ERRO":"O CAMPO NOME \U00E9 OBRIGAT\U00F3RIO"}"

Dim obj As Object = New JavaScriptSerializer().Deserialize(Of Object)(resposta.ToString())

How i solve the problem ?

Thank you

César Oliveira

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
998 questions
0 comments No comments
{count} votes

5 answers

Sort by: Most helpful
  1. Justin Jones 1 Reputation point
    2020-09-15T21:37:22.803+00:00

    @César Oliveira - your JSON string, resposta has an escape sequence that VS does not recognize. The "\U" within the JSON string is not supported. You should change the \U to \U.

    0 comments No comments

  2. César Oliveira 1 Reputation point
    2020-09-15T21:48:43.827+00:00

    Not is possíble.
    This json came of WebService
    I can't change the json

    How i solve the problema in vb.net ?

    Thank you

    0 comments No comments

  3. Dylan Zhu-MSFT 6,416 Reputation points
    2020-09-16T02:52:06.423+00:00

    Hi @César Oliveira ,

    You could use Chrw() function to recognize escape sequence in visual basic, which is like:

    "O CAMPO NOME \U00E9 OBRIGAT\U00F3RIO" -> "O CAMPO NOME" + ChrW(&HE9) + " OBRIGAT" + ChrW(&HF3) + "RIO"

    Best Regards,
    Dylan

    0 comments No comments

  4. César Oliveira 1 Reputation point
    2020-09-16T10:30:08.457+00:00

    No, i cant change the code json.
    it is necessary manipulate the variable resposta to acept the Escape sequence not recognized

    I tried other code but not work, it generate another exception. The code is:

    Dim resposta As String ="{"SUCCESS":0,"IDERRO":1,"ERRO":"O CAMPO NOME \U00E9 OBRIGAT\U00F3RIO"}"
    Dim stream = New MemoryStream(Encoding.UTF8.GetBytes(resposta.ToString()))
    Dim obj As Object = New JavaScriptSerializer().Deserialize(Of MensagemErro)(stream.toString())

    The exeption is System.ArgumentException: 'Invalid JSON primitive: System.IO.MemoryStream.'

    Thank you


  5. César Oliveira 1 Reputation point
    2020-09-17T11:54:55.797+00:00

    Thank you for all people,

    i solve the problem

    it is easy

    i convent the variable restultado to Lowercase. it work now.

    Thank you


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.