iOS - 如何将数组作为参数传递给AFNetworking(Objective-C)(iOS - How to pass array to AFNetworking as parameters (Objective-C))
我有一个php文件,我想用它来处理数据。 php文件包含一个以数组作为参数的函数。
php功能:
func((array)$input->foos as &$foo){ $request = mb_strtolower($foo->request); $found = false; $loopCount = 0; while($found === false && $loopCount < 3){ if($request === 'single' || $request === 'corner'){ $foo->request = $single_priority[$loopCount]; } else if($request === 'double'){ $foo->request = $double_priority[$loopCount]; } else if($request === 'quad'){ $foo->request = $quad_priority[$loopCount]; } $rooms = getRooms($foo, $link, $roomcounts[$foo->request]); if($room = $rooms->fetch_assoc()){ $found = true; if ($loopCount === 0){ if(!$link->query("REPLACE INTO reservations VALUES('{$room['room_id']}', '{$foo->user_id}', '{$foo->move_in_date}', '{$foo->move_out_date}', 'Incoming', '{$foo->date_added}')")){ $arr = array(); $arr['error'] = "Error: " . $link->error; echo json_encode($arr); die(); } array_push($result, array('user_id' => $foo->user_id, 'room_assigned' => $room['room_id'], 'request_status' => 0)); if(!$link->query("DELETE FROM res_waiting WHERE user_id = '{$foo->user_id}'")){ $arr = array(); $arr['error'] = "Error: " . $link->error; echo json_encode($arr); die(); } } else{ if(!$link->query("INSERT IGNORE INTO reservations VALUES('{$room['room_id']}', '{$foo->user_id}', '{$foo->move_in_date}', '{$foo->move_out_date}', 'Incoming', '{$foo->date_added}')")){ $arr = array(); $arr['error'] = "Error: " . $link->error; echo json_encode($arr); die(); } array_push($result, array('user_id' => $foo->user_id, 'room_assigned' => $room['room_id'], 'request_status' => 1)); } } $loopCount += 1; } if (found === false){ array_push($result, array('user_id' => $foo->user_id, 'room_assigned' => 0, 'request_status' => 2)); } }
我正在使用AFNetworking将php代码连接到Objective-C
Objective-C代码:
-(void) connectToPHP:(NSArray *)parameters { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; NSString *URLString = [[NSString alloc] initWithFormat:@"ip.address/email.php"]; [manager POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSData *jsonData = responseObject; NSError * error=nil; id reponse = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; NSLog(@"JSON response: %@", [reponse objectForKey:@"response"]); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if(error){ NSLog(@"%@ Error:", error); } }]; }
功能调用:
NSDictionary *foo = @{ @"id" : @"2011011", @"request" : @"single", @"gender" : @"M", @"username" : @"name", }; NSArray *arr = [NSArray arrayWithObjects:foo, nil]; [self connectToPHP:arr];
但是当我运行它时,php文件中的函数无法正常运行,我收到错误。 我认为这与我如何将数组作为参数传递有关。
I have a php file which I want to use to process data. The php file contains a function that takes in an array as parameters.
php function:
func((array)$input->foos as &$foo){ $request = mb_strtolower($foo->request); $found = false; $loopCount = 0; while($found === false && $loopCount < 3){ if($request === 'single' || $request === 'corner'){ $foo->request = $single_priority[$loopCount]; } else if($request === 'double'){ $foo->request = $double_priority[$loopCount]; } else if($request === 'quad'){ $foo->request = $quad_priority[$loopCount]; } $rooms = getRooms($foo, $link, $roomcounts[$foo->request]); if($room = $rooms->fetch_assoc()){ $found = true; if ($loopCount === 0){ if(!$link->query("REPLACE INTO reservations VALUES('{$room['room_id']}', '{$foo->user_id}', '{$foo->move_in_date}', '{$foo->move_out_date}', 'Incoming', '{$foo->date_added}')")){ $arr = array(); $arr['error'] = "Error: " . $link->error; echo json_encode($arr); die(); } array_push($result, array('user_id' => $foo->user_id, 'room_assigned' => $room['room_id'], 'request_status' => 0)); if(!$link->query("DELETE FROM res_waiting WHERE user_id = '{$foo->user_id}'")){ $arr = array(); $arr['error'] = "Error: " . $link->error; echo json_encode($arr); die(); } } else{ if(!$link->query("INSERT IGNORE INTO reservations VALUES('{$room['room_id']}', '{$foo->user_id}', '{$foo->move_in_date}', '{$foo->move_out_date}', 'Incoming', '{$foo->date_added}')")){ $arr = array(); $arr['error'] = "Error: " . $link->error; echo json_encode($arr); die(); } array_push($result, array('user_id' => $foo->user_id, 'room_assigned' => $room['room_id'], 'request_status' => 1)); } } $loopCount += 1; } if (found === false){ array_push($result, array('user_id' => $foo->user_id, 'room_assigned' => 0, 'request_status' => 2)); } }
I am using AFNetworking to connect to the php code to Objective-C
Objective-C code:
-(void) connectToPHP:(NSArray *)parameters { AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; manager.requestSerializer = [AFJSONRequestSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; NSString *URLString = [[NSString alloc] initWithFormat:@"ip.address/email.php"]; [manager POST:URLString parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject) { NSData *jsonData = responseObject; NSError * error=nil; id reponse = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; NSLog(@"JSON response: %@", [reponse objectForKey:@"response"]); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { if(error){ NSLog(@"%@ Error:", error); } }]; }
Function call:
NSDictionary *foo = @{ @"id" : @"2011011", @"request" : @"single", @"gender" : @"M", @"username" : @"name", }; NSArray *arr = [NSArray arrayWithObjects:foo, nil]; [self connectToPHP:arr];
However when I run this the function in the php file does not run correctly and I get an error. I think it has to do with how I pass the array as parameters.
原文:https://stackoverflow.com/questions/45777252
满意答案
VSTO用于不同的东西(它用于创建Visio插件),它与你所追求的无关。
您可以在C#应用程序中使用两个Visio控件:Visio Viewer控件(允许您在C#应用程序中查看Visio绘图)和Visio Drawing控件(允许您在C#应用程序中修改Visio绘图)。 要获取它们,您必须安装Visio或Visio Viewer。
要在工具箱中获取它们:
- 右键单击工具箱 - >选择项目..
- 在“选择工具箱项”对话框中,选择“COM组件”选项卡
- 选择“Microsoft Visio绘图控件”(绘图控件)或“Visio文档”(查看器),单击“确定”
- 现在你应该在工具箱中获得控制权。
VSTO is for a different thing (it's for creating Visio addins), it is, well, unrelated to what you are after.
There are two Visio controls you can use in your C# application: Visio Viewer control (allows you to view Visio drawing in a C# application), and Visio Drawing control (allows you to modify a Visio drawing in your C# application). To get them, you must have either Visio or Visio Viewer installed.
To get them in your toolbox:
- Right click the toolbox -> Choose items..
- In the "Choose toolbox items" dialog, select tab "COM components"
- Select either "Microsoft Visio Drawing control" (drawing control) or "Visio Document" (viewer), click OK
- Now you should get your control in the toolbox.
相关问答
更多如何添加“用于Office Runtime的MS Visual Studio 20xx工具”?(How to add “MS Visual Studio 20xx Tools for Office Runtime”?)
为Office Second Edition安装Visual Studio 2005工具 - 将Visio面板添加到工具箱(Installed Visual Studio 2005 Tools for Office Second Edition - Add Visio Panel to Toolbox)
用于Office的Visual Studio工具(VSTO) - 寻找一些用户指南(Visual Studio Tools for Office (VSTO) - Looking for some User Guide)
Visual Studio社区,Office SDK(Visual Studio Community, Office SDK)
用于Office的Visual Studio 2013 RC和Visual Studio工具 - TF400422使用Excel时出错(Visual Studio 2013 RC & Visual Studio Tools for Office - TF400422 Error when using Excel)
使用Visual Studio 2010(VSTO)进行Office开发,需要考虑的事项(Office development with Visual Studio 2010 (VSTO), things to consider)
安装Visual Studio和SQL Server 2005后,Office 2007更新(Office 2007 updates after installing Visual Studio & SQL Server 2005)
将GLcontrol添加到visual studio工具箱中(adding GLcontrol to visual studio toolbox)
Visual Studio Tools for Office是否需要安装Office?(Does Visual Studio Tools for Office require Office to be installed?)
Office 2003在Visual Studio 2005 Profesional,Win XP中使用VSTO 2005 SE和C#添加(Office 2003 Add In using VSTO 2005 SE and C# in Visual Studio 2005 Profesional, Win XP)
相关文章
更多《iPhone开发视频教程:iOS开发Objective-C视频教程》完整版
[ios视频教程] 无限互联ios视频教程全集之objective-c部分
《Objective-C 程序设计(第4版)》扫描版[PDF]
Objective C--享元模式
《渥瑞达:Objective-C软件开发视频教程(完整版)》共八天更新完毕
iOS设备的越狱方法
iOS设备的越狱方法
ios获取ip地址
尚学堂ios视频教程
《iPhone开发视频教程:iOS开发视频课程》持续更新,敬请期待
最新问答
更多您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
在计算机拍照在哪里进入
使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
单页应用程序:页面重新加载(Single Page Application: page reload)
在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!