locked
Json and Exceptions RRS feed

  • Question

  • Hello People

    I have a problem with a Json and two Exceptions. I have two cods, The codes generate exceptions.
    I can't change the json. He came Webservice.
    i have manipulate the variable resposta to not have problem.

    1º Code:

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

    This code generate this exception: SYSTEM.ARGUMENTEXCEPTION: 'ESCAPE SEQUENCE NOT RECOGNIZED.. (48):

    2º Code:

    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())

    This code generate this exception: System.ArgumentException: 'Invalid JSON primitive: System.IO.MemoryStream.'

    Help me to solve this problem, please.

    Thank you
    Wednesday, September 16, 2020 4:14 PM

Answers

  • Hi Malainho,

    It seems that your problem has been solved, so please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue. Thanks.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Malainho Saturday, October 3, 2020 11:26 PM
    Friday, September 18, 2020 3:20 AM

All replies

  • I have two cods.

    Is this a cooking or fishing question?

    Why not using System.Text.Json or Newtonsoft.Json?

    The error itself means that an escaped Unicode character could not be proberly deserialized. Please craft a concise console application showing that behavior. Per definition the U in the escaped string must be lowercase. So test it with a lowercase u.

    Wednesday, September 16, 2020 4:26 PM
  • Thank you for all people,

    i solve the problem

    it  is easy

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

    Thank you
    Thursday, September 17, 2020 11:58 AM
  • That is what I wrote. JSON Unicode escaping requires a lowercase u.
    Thursday, September 17, 2020 12:44 PM
  • Hi Malainho,

    It seems that your problem has been solved, so please click the "Mark as Answer" Link at the bottom of the correct post(s), so that it will help other members to find the solution quickly if they face a similar issue. Thanks.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by Malainho Saturday, October 3, 2020 11:26 PM
    Friday, September 18, 2020 3:20 AM