문제

How do I get true/false (instead of "true"/"false") in json from a NSDictionary using NSJSONSerialization dataWithJSONObject? What keys should I store in the dictionary to get that?

도움이 되었습니까?

해결책

NSNumber objects containing a BOOL are mapped to JSON "true" and "false". So just use @YES, @NO, or generally @(someBOOL). For example:

NSDictionary *dict = @{@"this is": @YES};
NSData *data = [NSJSONSerialization dataWithJSONObject:dict options:0 error:NULL];
NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// {"this is":true}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top