我有两个不同的应用程序在两个不同的 Mac 上运行:一个客户端和一个服务器。他们使用 HTTP 进行通信。服务器有一个 HTTP 服务器,它发布封装发送的数据的 plist 文件。
例如
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>sensorName</key>
<string>external</string>
<key>temperature</key>
<real>8.8</real>
</dict>
</plist>
客户端使用 HTTPRequest 并像这样收集数据:
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
DDLogVerbose(@"URL Connection succeeded! Received %ld bytes of data",[testReceivedData length]);
NSString *errorDescription = nil;
NSPropertyListFormat format;
NSDictionary *incomingPlist = [NSPropertyListSerialization propertyListFromData:testReceivedData
mutabilityOption:NSPropertyListImmutable
format:&format
errorDescription:&errorDescription];
if (errorDescription)
{
DDLogError(@"Error converting data from web into plist: %@", errorDescription);
return;
}
DDLogVerbose(@"We got a plist from the server: %@", incomingPlist);
NSString *sensorName;
switch ([self currentCommandType]) {
case MFRemoteCommandTypeSensorIndex:
[self setSensorNames:[incomingPlist objectForKey:@"sensorNames"]];
break;
case MFRemoteCommandTypeTemperature:
sensorName = [incomingPlist objectForKey:@"sensorName"];
if (!sensorName)
{
DDLogError(@"Could not get sensorname from temperature plist: %@", incomingPlist);
break;
}
[self didReceiveTemperatureReading:(NSNumber *)[incomingPlist objectForKey:@"temperature"] ForSensorName:sensorName];
break;
default:
DDLogError(@"We should never get here.");
break;
}
[self clearCurrentRequest];
}
到目前为止一切都很好......两个应用程序之间的数据流动良好,世界上一切都很好。
但是,有时,我无法弄清楚原因是什么,客户会错误地解释温度值。即,而不是将温度 NSNumber 解释为 8.8,而不是将其解释为 8.800000000000001 或 9.2 为 9.199999999999999
有谁知道它为什么会这样做?奇怪的是,当它这样做时似乎没有任何模式......
提前感谢您的帮助。