Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将customobject作为参数从目标C传递到C++;_C++_Ios_Objective C - Fatal编程技术网

C++ 将customobject作为参数从目标C传递到C++;

C++ 将customobject作为参数从目标C传递到C++;,c++,ios,objective-c,C++,Ios,Objective C,在我的应用程序中,我正在从objective-c调用一个c++函数,该函数将参数作为键值pair 我能够成功地传递一对std::map args,但现在我想传递一个字典 我试着用谷歌搜索它,但我无法理解它 为了更好地理解,以下是我的代码: +(void)createChatRoom:(NSDictionary *)chatRoomInfo forCompanyJSON:(NSDictionary *)companyJsonString completion:(void(^)(BOOL))comp

在我的应用程序中,我正在从
objective-c
调用一个
c++
函数,该函数将参数作为键值
pair

我能够成功地传递一对
std::map args
,但现在我想传递一个字典

我试着用谷歌搜索它,但我无法理解它

为了更好地理解,以下是我的代码:

+(void)createChatRoom:(NSDictionary *)chatRoomInfo forCompanyJSON:(NSDictionary *)companyJsonString completion:(void(^)(BOOL))completionHandler
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_LOW, 0), ^{
        @autoreleasepool{
            NSString *strOwner = [chatRoomInfo objectForKey:@"owner"];
            NSString *strCreator = [chatRoomInfo objectForKey:@"creator"];
            NSString *strSubject = [chatRoomInfo objectForKey:@"subject"];
            NSString *strProfilePic = [chatRoomInfo objectForKey:@"profilePic"];
            NSInteger isPublic = [[chatRoomInfo objectForKey:@"isPublic"]boolValue] ? 1 :0;
            NSString *strDescription = [chatRoomInfo objectForKey:@"description"];
            NSString *strStatus = [chatRoomInfo objectForKey:@"status"];

            std::map<std::string, std::string> args;
            args["owner"] = std::string([strOwner UTF8String]);
            args["creator"] = std::string([strCreator UTF8String]);
            args["subject"] = std::string([strSubject UTF8String]);
            args["profilePic"] = std::string([strProfilePic UTF8String]);
            args["isPublic"] = isPublic;
            args["description"] = std::string([strDescription UTF8String]);
            args["status"] = std::string([strStatus UTF8String]);
            args["company"] = **//Here i want to pass dictonary**

            //Code to set the Log file path for iOS app, to avoid the crash on Logger
            //Code to call the web service
            WS::Response resp = WS::createRoom(args);

            //Print the web service response in console window
            NSString *response_body = [NSString stringWithCString:resp.body.c_str() encoding:[NSString defaultCStringEncoding]];
            NSLog(@"%@", response_body);
            NSLog(@"Response fetched successfully");
        }
    });
}
+(void)createChatRoom:(NSDictionary*)公司聊天室信息JSON:(NSDictionary*)公司JSON字符串完成:(void(^)(BOOL))完成处理程序
{
调度异步(调度获取全局队列(调度队列优先级低,0)^{
@自动释放池{
NSString*strOwner=[chatRoomInfo objectForKey:@“所有者”];
NSString*strCreator=[chatRoomInfo objectForKey:@“creator”];
NSString*strSubject=[chatRoomInfo objectForKey:@“subject”];
NSString*strProfilePic=[chatRoomInfo objectForKey:@“profilePic”];
NSInteger isPublic=[[chatRoomInfo objectForKey:@“isPublic”]boolValue]?1:0;
NSString*strDescription=[chatRoomInfo objectForKey:@“description”];
NSString*strStatus=[chatRoomInfo objectForKey:@“status”];
映射参数;
args[“owner”]=std::string([strOwner UTF8String]);
args[“creator”]=std::string([strCreator UTF8String]);
args[“subject”]=std::string([strSubject UTF8String]);
args[“profilePic”]=std::string([strProfilePic UTF8String]);
args[“isPublic”]=isPublic;
args[“description”]=std::string([strDescription UTF8String]);
args[“status”]=std::string([strStatus UTF8String]);
args[“company”]=**//我想在这里通过口述**
//用于设置iOS应用程序的日志文件路径的代码,以避免记录器崩溃
//调用web服务的代码
WS::Response resp=WS::createRoom(args);
//在控制台窗口中打印web服务响应
NSString*response_body=[NSString stringWithCString:resp.body.c_str()编码:[NSString defaultCStringEncoding]];
NSLog(@“%@”,响应体);
NSLog(@“已成功获取响应”);
}
});
}

任何帮助或建议都会对我有帮助。

要实现它,您必须将
args
声明为
std::map

std::map args;
args[“所有者”]=strOwner;
args[“创建者”]=strCreator;
args[“subject”]=strSubject;
args[“profilePic”]=strProfilePic;
args[“isPublic”]=@(isPublic);
args[“description”]=strDescription;
args[“status”]=strStatus;
args[“公司”]=[NSDictionary new];

将字典转换为json字符串,并像std::字符串一样正常传递。当你们想使用字典时,把json字符串转换成字典。但我想传递object,有并没有像我们在Objective c中使用“id”或在Swiftman中使用“any”这样的方法呢。它似乎在工作,但行参数[“isPublic”]=@isPublic;为@My bad指定错误时,应该是
@(isPublic)
,而不是
@isPublic
。更新了我的答案。明白了。再次感谢(:
std::map<std::string, id> args;
args["owner"] = strOwner;
args["creator"] = strCreator;
args["subject"] = strSubject;
args["profilePic"] = strProfilePic;
args["isPublic"] = @(isPublic);
args["description"] = strDescription;
args["status"] = strStatus;
args["company"] = [NSDictionary new];