λ³Έλ¬Έ λ°”λ‘œκ°€κΈ°
πŸ’š 개발/iOS

[iOS] Objective-C NSMutableDictionary λ₯Ό json ν˜•νƒœλ‘œ λ³€ν™˜

by devshin.kr 2021. 10. 6.
728x90

iOS (Objective-C) μ—μ„œ JSON ν˜•νƒœλ‘œ http 톡신을 ν•˜κΈ° μœ„ν•΄ json ν˜•νƒœλ‘œ λ³€ν™˜μ„ ν•˜λŠ” μ½”λ“œμ΄λ‹€.
NSMutableDictionary ν˜•νƒœμ˜ 데이터λ₯Ό NSJSONSerialization 을 μ΄μš©ν•΄ NSData 둜 λ³€ν™˜ν•œ ν›„, λ‹€μ‹œ NSString 으둜 λ³€ν™˜ν•œλ‹€.

NSMutableDictionary *retDic = [[NSMutableDictionary alloc]init];
[retDic setValue:κ°’1 forKey:@"ν‚€1"];
[retDic setValue:κ°’2 forKey:@"ν‚€2"];

NSData *requestData = [NSJSONSerialization dataWithJSONObject:retDic options:0 error:nil];

NSString *requestJson = [[NSString alloc] initWithData:requestData encoding:NSUTF8StringEncoding];

 

λŒ“κΈ€