Pregunta

I'm trying to create a json string of the following format in WP8

{"user": { "email": "abc@gmail.me", "password": "abc"}}

I have created { "email": "abc@gmail.me", "password": "abc*"} part like

        string emailText = confirmEmailTbox.Text;
        string passText = "password";
        string pass = confirmPasswordPBox.Password;

        Dictionary<string, string> jsonChild = new Dictionary<string, string>();
        jsonChild.Add(emailText, email);
        jsonChild.Add(passText, pass);
        string jsonStringChild = JsonConvert.SerializeObject(jsonChild, Formatting.None);

But how do i put all this into the other object as in how do i add the "user" to the jsonString

Edit: Both formats

{
"user": {
  "email": "abc@gmail.me"
  "password": "12345"
  }
}
¿Fue útil?

Solución

Leverage the anonymous objects available in C#:

 var data = new { user = new { email=email, password = pass}};
 string jsonStringChild = JsonConvert.SerializeObject(data);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top