我的应用程序中有一个方法向服务器发送请求以检查用户当前是否已登录。此 ColdFusion 函数返回类型 boolean 。当我 NSLog 返回的数据时,我得到的是:
<header/> 。
目前,为了确定它返回的是 true 还是 false,我正在该返回的字符串中搜索子字符串“true”。这似乎不是一个好的解决方案。我的问题是,有没有更好的方法从这个函数中获取一个 Objective-C BOOL ?如果更改 ColdFusion 功能更好,我很幸运可以做到。谢谢!
ColdFusion 功能:
<cffunction name="loggedIn" returnType="Boolean" output="false" access="remote">
<cfargument name="sessionID" type="UUID" required="true">
<cfquery name="q_session" datasource="#request.db_dsn#">
SELECT ...
</cfquery>
<cfreturn q_session.recordCount gte 1>
</cffunction>
Objective-C 方法片段:
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:myURLVar];
[request setHTTPMethod"OST"];
[request setValue"application/x-www-form-urlencoded" forHTTPHeaderField"Content-Type"];
[request setValue:postLength forHTTPHeaderField"Content-Length"];
[request setValue"application/json" forHTTPHeaderField"Accept"];
[request setHTTPBody:postData];
NSError *requestError = [[NSError alloc] init];
NSHTTPURLResponse *response = nil;
NSData *urlData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&requestError];
NSString *responseData = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
NSLog(@"%@", responseData);
if ([responseData rangeOfString"true" options:NSCaseInsensitiveSearch].location != NSNotFound){
sessionIsActive = YES;
}
Best Answer-推荐答案 strong>
我认为您可以将 returnFormat="plain" 添加到您的 cffunction 。
plain: ensure that the return value is a type that ColdFusion can convert directly to a string, and return the string value without serialization. Valid types include all simple types, such as numbers, and XML objects. If the return value is a complex type, such as an array, or a binary value, ColdFusion generates an error. If you specify a returntype attribute, its value must be any, boolean, date, guid, numeric, string, uuid, variablename, or XML; otherwise, ColdFusion generates an error.
默认情况下,ColdFusion 将除 XML 之外的所有返回类型(包括简单返回类型)序列化为 WDDX 格式,并将 XML 数据作为 XML 文本返回。
应该只给你字符串,这样解析起来会更简单。
[ source ]
关于ios - 从 Objective-C 中的 ColdFusion boolean 返回类型获取 BOOL 的更好方法?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/23204279/
|