1
我困住了一個問題!JSON的NSMutableDictionary
我有一個JSON字符串,如:
{ 「用戶名」: 「用戶名」, 「密碼」: 「密碼」}
我建這個JSON字符串中包含的Xcode:
NSMutableDictionary *jsonDict = [[NSMutableDictionary alloc] init];
[jsonDict setValue:self.usernameField.text forKey:@"UserName"];
[jsonDict setValue:self.passwordField.text forKey:@"PassWord"];
NSLog(@"Dict: %@",jsonDict);
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:jsonDict options:kNilOptions error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
NSLog(@"JSON String: %@",jsonString);
NSString *postStr = [NSString stringWithFormat:@"%@",jsonString];
但現在我想用JSON字符串,如:
{ "comp": [
{ "id": "1" },
{ "id": "2" },
{ "id": "3" }
],
"contact": [
{ "mail": "[email protected]", "name": "Name" },
{ "mail": "[email protected]", "name": "Name" }
]
}
但我該怎麼做?有人可以幫我嗎?