我是 Objective-C 和 iOS 开发的新手,正在尝试编写一种生成 JSON 字符串的方法,但是当我 NSLog 时,我得到一堆十六进制代码(我猜它们是指针地址)有人可以看看这个方法并告诉我做错了什么..
-(NSData *)generateInputJSON
{
NSError* error = nil;
NSString* region = [[NSLocale currentLocale]localeIdentifier];
NSString* language = [[NSLocale preferredLanguages]objectAtIndex:0];
NSMutableDictionary* properties = [NSMutableDictionary dictionaryWithObjectsAndKeys:
_sphereODNumber,@"sphereOD",
_sphereOSNumber,@"sphereOS",
_cylinderODNumber,@"cylinderOD",
_cylinderOSNumber,@"cylinderOS",
_visionCorrection,@"visionCorrection",
region,@"region",
language,@"language",
nil];
if([_visionCorrection isEqualToString:@"multiFocal"] ||
[_visionCorrection isEqualToString: @"progressive"])
{
[properties setValue:_addODNumber forKey:@"addOD"];
[properties setValue:_addOSNumber forKey:@"addOS"];
}
if([_visionCorrection isEqualToString: @"progressive"])
{
[properties setValue:_fittingHeightNumber forKeyPath:@"fittingHeight"];
}
NSData* inputJSON = [NSJSONSerialization dataWithJSONObject:properties options:NSJSONWritingPrettyPrinted error:&error];
return inputJSON;
}
我的日志返回:
<7b0a2020 226c616e 67756167 6522203a 2022656e 222c0a20 20227669 73696f6e 436f7272 65637469 6f6e2220 3a202270 726f6772 65737369 7665222c 0a202022 6164644f 4422203a 20342e35 2c0a2020 22616464 4f532220 3a20342e 352c0a20 20227370 68657265 4f532220 3a20342e 352c0a20 20227265 67696f6e 22203a20 22656e5f 5553222c 0a202022 63796c69 6e646572 4f532220 3a20342e 352c0a20 20226669 7474696e 67486569 67687422 203a2031 372c0a20 20227370 68657265 4f442220 3a20342e 352c0a20 20226379 6c696e64 65724f44 22203a20 342e350a 7d>