WP8中的Json格式

时间:2014-04-09 08:43:20

标签: windows-phone-8 json.net

我正在尝试在WP8中创建以下格式的json字符串

  

{“user”:{“email”:“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"
  }
}

1 个答案:

答案 0 :(得分:3)

利用C#中可用的匿名对象:

 var data = new { user = new { email=email, password = pass}};
 string jsonStringChild = JsonConvert.SerializeObject(data);