Reputation: 29
How to format this line of code so that in "myusername" you can enter the text typed from the phone keyboard, e.g. instead of "myusername" I would like there to be email.Text. email.text must be in quotation marks. Sorry for my bad english.
string jsonData = @"{""username"" : ""myusername"", ""password"" : ""mypassword""}";
I tried this way but it still doesn't work
string jsonData = "{ \"Email\" : \"{0}\" ,\"Password\" : \"{1}\"}";
string jsonMain = String.Format(jsonData, email.Text, password.Text);
Upvotes: 0
Views: 49
Reputation: 15806
You can Serializing and Deserializing JSON
with follow codes:
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
testModel model = new testModel();
model.Email = "abc";
model.username = "allen";
string jsonString;
jsonString = JsonConvert.SerializeObject(model);
//deserialize
testModel deserializedmodel = JsonConvert.DeserializeObject<testModel>(jsonString);
}
}
public class testModel
{
public string Email { get; set; }
public string username { get; set; }
}
Upvotes: 1