Reputation: 330
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
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
Reputation: 330
string json = @" {
'MemberName':'" + txtName.Text + @"',
'MemeberEmail':'" + txtEmail.Text + @"',
'MemberPassword':'" + txtPassword.Text + @"'
}";
Upvotes: 1
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