你好我嘗試使用的NSDictionary 到目前爲止創建JSON字符串,我不能讓這個JSONIOS的NSDictionary創建JSON
{"user":{"username":"test","email":"[email protected]", "password":"123456789","password_confirmation":"123456789"}
這裏是我的代碼:
NSDictionary *jsonUserDictinary = [NSDictionary dictionaryWithObjectsAndKeys:
[usernameText text], @"username",
[passwordText text], @"password" ,
[emailText text], @"email",
[confirmText text], @"password_confirmation",
nil];
NSDictionary *jsonSignUpDictionary = [NSDictionary dictionaryWithObjectsAndKeys:jsonUserDictinary, @"user",nil];
NSData *jsonSignUpData = [NSJSONSerialization dataWithJSONObject:jsonSignUpDictionary options:NSJSONWritingPrettyPrinted error: nil];
NSString *jsonSignUp = [[NSString alloc] initWithData:jsonSignUpData encoding:NSUTF8StringEncoding];
NSLog(@"json data string:\n%@", jsonSignUp);
現在我想創造這個JSON:
{"user":{"username":"test","email":"[email protected]", "password":"123456789","password_confirmation":"123456789"},"device":{"token":"654C4DB3-3F68-4969-8ED2-80EA16B46EB0"}}
,但我不能找到一種方法來添加「設備」對象
你做的正是你爲用戶嵌套字典同樣的事情... – Wain