• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 从 Objective-C 中的 ColdFusion boolean 返回类型获取 BOOL 的更好方法?

[复制链接]
菜鸟教程小白 发表于 2022-12-12 21:47:02 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我的应用程序中有一个方法向服务器发送请求以检查用户当前是否已登录。此 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-推荐答案


我认为您可以将 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap