0

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

12
  • 1
    What's the error? Commented Jun 9, 2019 at 8:43
  • 'MemberName': ' abc', --------if i am writting member name like this it is accepting but not in double quotes Commented Jun 9, 2019 at 8:45
  • You might want to add single quotes before/after the double quotes around the Textbox-string. Commented Jun 9, 2019 at 8:47
  • it is written in c# i need textbox value Commented Jun 9, 2019 at 8:48
  • Also I need to know what the Exception is saying. I know that it's written in C# this does not help. Commented Jun 9, 2019 at 8:49

3 Answers 3

1

string json = @" {

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


       }";
Sign up to request clarification or add additional context in comments.

1 Comment

That is the answer
0

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.

Comments

0

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'


    }";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.