Jitender
Jitender

Reputation: 330

How to write textbox value in string format

I am trying to get textbox value in a JSON format, but it is giving an error when I am putting "+txtName.Text+" what is the correct format to write textbox value in string

 string json = @"
        {


            'MemberName':"+txtName.Text+", 
            'MemeberEmail':'mack @mack.com',
            'MemberPassword':'111'


        }";

Code is above

Upvotes: 0

Views: 395

Answers (3)

Norse
Norse

Reputation: 121

When using the Verbatim Literal (@) you need to use "" as an escape sequence within the string. A simple " will end the string. Think of it like the \" in your ordinary string.

string json = @"
    {


        'MemberName':""+txtName.Text+"", 
        'MemeberEmail':'mack @mack.com',
        'MemberPassword':'111'


    }";

Upvotes: 0

Jitender
Jitender

Reputation: 330

string json = @" {

            'MemberName':'" + txtName.Text + @"', 
            'MemeberEmail':'" + txtEmail.Text + @"',
            'MemberPassword':'" + txtPassword.Text + @"'


       }";

Upvotes: 1

Shahzad Khan
Shahzad Khan

Reputation: 530

Just do the below thing it will help you out from cause.

var mytext = "mytextbox";
            var json =
                new
                {
                    MemberName = mytext,
                    MemeberEmail = "mack @mack.com",
                    MemberPassword = "111"
                };
            return JsonConvert.SerializeObject(json);

for JsonConvert use the Newtonsoft nuget packege.

Upvotes: 0

Related Questions