0

I have same problem like this . But when I try this code :

            var json = (new MyResponse { message = "The user name or password is incorrect" }).ToJsonString();
            context.SetError(new string(' ',json.Length-12)); 
            context.Response.Write(json);

-

 public class MyResponse
    {
        public string access_token { get; set; }
        public string message { get; set; }
    }

I get "syntax error". Because text response is:

{"access_token":null,"message":"The user name or password is incorrect"}{"error":" "}

I can't remove {"error":" "}

Adem Aygun
  • 550
  • 2
  • 6
  • 25

1 Answers1

0

The issue seems to be with the MyResponse class that or its parent class could contain a property named access_token which is shown in the Response

Fix to get your desired output to create a new response class like this

public class MyNewReponse
{
  public string message {get;set;}
}

And then create the response using that class

var json = (new MyNewReponse { message = "The user name or password is incorrect" }).ToJsonString();
Ipsit Gaur
  • 2,872
  • 1
  • 23
  • 38