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":" "}

0

1 Answer 1

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.