我正试图在WP8 中创建以下格式的json字符串
{"用户":{"电子邮件":abc@gmail.me","password":"abc"}}
我已经创建了类似的{ "email": "abc@gmail.me", "password": "abc*"}
部件
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);
但是,我如何将所有这些放入另一个对象中,就像我如何将"用户"添加到jsonString
编辑:两种格式的
{
"user": {
"email": "abc@gmail.me"
"password": "12345"
}
}
利用C#中可用的匿名对象:
var data = new { user = new { email=email, password = pass}};
string jsonStringChild = JsonConvert.SerializeObject(data);