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
2022-06-26 20:06

满意答案

VSTO用于不同的东西(它用于创建Visio插件),它与你所追求的无关。

您可以在C#应用程序中使用两个Visio控件:Visio Viewer控件(允许您在C#应用程序中查看Visio绘图)和Visio Drawing控件(允许您在C#应用程序中修改Visio绘图)。 要获取它们,您必须安装Visio或Visio Viewer。

要在工具箱中获取它们:

  1. 右键单击工具箱 - >选择项目..
  2. 在“选择工具箱项”对话框中,选择“COM组件”选项卡
  3. 选择“Microsoft Visio绘图控件”(绘图控件)或“Visio文档”(查看器),单击“确定”
  4. 现在你应该在工具箱中获得控制权。

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:

  1. Right click the toolbox -> Choose items..
  2. In the "Choose toolbox items" dialog, select tab "COM components"
  3. Select either "Microsoft Visio Drawing control" (drawing control) or "Visio Document" (viewer), click OK
  4. 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”?)

虽然你手动做了,但它会正常工作。 或者,您可以转到项目属性,发布选项卡,然后单击前提条件按钮以显示预先请求对话框,您应该能够看到VSTOR40以及其他引导程序组件。 如果您在那里没有看到特定的一个,则可能有两个原因: 您的C:\ Program Files文件(x86)\ Microsoft SDKs \ Windows \ v8.0A \ Bootstrapper \ Packages文件夹中没有引导程序包(用VS7.0替换为v7.0) 您的product.xml(位于上述位置)包含不正确的信息...

为Office Second Edition安装Visual Studio 2005工具 - 将Visio面板添加到工具箱(Installed Visual Studio 2005 Tools for Office Second Edition - Add Visio Panel to Toolbox)

VSTO用于不同的东西(它用于创建Visio插件),它与你所追求的无关。 您可以在C#应用程序中使用两个Visio控件:Visio Viewer控件(允许您在C#应用程序中查看Visio绘图)和Visio Drawing控件(允许您在C#应用程序中修改Visio绘图)。 要获取它们,您必须安装Visio或Visio Viewer。 要在工具箱中获取它们: 右键单击工具箱 - >选择项目.. 在“选择工具箱项”对话框中,选择“COM组件”选项卡 选择“Microsoft Visio绘图控件”(绘图控...

用于Office的Visual Studio工具(VSTO) - 寻找一些用户指南(Visual Studio Tools for Office (VSTO) - Looking for some User Guide)

MSDN中的Excel解决方案部分提供了所有必需的信息。 我建议从演练开始:为Excel创建第一个应用程序级外接程序文章。 The Excel Solutions section in MSDN provides all the required information. I'd suggest starting from the Walkthrough: Creating Your First Application-Level Add-in for Excel article.

Visual Studio社区,Office SDK(Visual Studio Community, Office SDK)

能够通过安装VS ultimate并检查Office SDK来修复它。 Was able to fix it by installing VS ultimate and checking the 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)

我有同样的问题,瞪眼但没有成功。 问题是一切都工作到今天。 所以它不兼容64位对32位。 此外,Outlook查询工作正常。 我通过从excel,团队选项卡打开查询来绕过问题。 I have same problem, goggled it but with no success. Problem is that everything worked till today. So it isn't compatibility 64bit vs 32bit. Also, Outlook queries...

安装Visual Studio和SQL Server 2005后,Office 2007更新(Office 2007 updates after installing Visual Studio & SQL Server 2005)

我发现Microsoft Visual Studio Web Authoring组件是罪魁祸首。 我决定只安装更新。 I found out that the Microsoft Visual Studio Web Authoring Component was the culprit. I decided to just install the updates.

将GLcontrol添加到visual studio工具箱中(adding GLcontrol to visual studio toolbox)

仔细检查您的项目引用,您需要OpenTK.dll和OpenTK.GLControl.dll 。 将GLControl添加到WinForms工具箱的内容将在文档中的“构建基于Windows.Forms + GLControl的应用程序”中介绍。 首先,创建一个表格,您可以在其上放置GLControl。 右键单击工具箱的空白区域,选择“选择项目...”并浏览OpenTK.GLControl.dll 。 确保您可以找到“.NET Framework组件”中列出的“GLControl”,如下图所示。 然后...

Visual Studio Tools for Office是否需要安装Office?(Does Visual Studio Tools for Office require Office to be installed?)

系统要求说明如下: Microsoft Office版本:开发和运行使用VSTO 2005或VSTO 2005 SE构建的Office自定义项至少需要以下Microsoft Office版本之一 Microsoft Office Professional Edition 2003 Microsoft Office Standard Edition 2003(仅适用于标准版的应用程序级加载项) Microsoft Word 2003 Microsoft Excel 2003 Microsoft In...

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)

我不羡慕你 - 我不需要在一段时间内部署一个2003加载项,我不能说这些天我想念。 它本身不是答案,但我注意到您提供的MSDN链接是指Office 2007; 这篇文章特定于Office 2003,可能很有用: http://msdn.microsoft.com/en-us/library/aa537179(office.11).aspx 我记得在使用Excel 2003加载项时遇到了一些问题,也许你也会在我的一些旧帖子中找到想法,比如这个: http : //clear-lines.com/bl...

相关文章

更多

《iPhone开发视频教程:iOS开发Objective-C视频教程》完整版

中文名: iPhone开发视频教程:iOS开发Objective-C视频教程 别名: iOS开发 ...

[ios视频教程] 无限互联ios视频教程全集之objective-c部分

6.5【无限互联】自动释放池和ARC.mov 无限互联iOS开发视频教程:7.1.NSFileHand ...

《Objective-C 程序设计(第4版)》扫描版[PDF]

中文名: Objective-C 程序设计(第4版) 作者: (美)Stephen G. Koc ...

Objective C--享元模式

http://www.devdiv.com/iOS_iPhone-Objective_C--%E4%B ...

《渥瑞达:Objective-C软件开发视频教程(完整版)》共八天更新完毕

objective-c语言整体开发环境介绍(第一天):介绍了oc语言的发展过程,oc语言的发展前景,o ...

iOS设备的越狱方法

最近公司的事情很忙,在开发一个类似于微信的App,经常加班,所以也没有时间去更新微信公众账号的内容了。 ...

iOS设备的越狱方法

本文转载至http://www.cnblogs.com/easonoutlook/p/3280232. ...

ios获取ip地址

进来接微信支付,后台要传ip地址,so~ 首先要导这些头文件 1 #include &lt;s ...

尚学堂ios视频教程

C语言课程简介 本C语言入门视频教程由郭崇智主讲,主要讲了c语言程序设计的基础篇,比如C语言的数 ...

《iPhone开发视频教程:iOS开发视频课程》持续更新,敬请期待

中文名: iPhone开发视频教程:iOS开发视频课程 别名: iOS开发视频教程:iPhone ...

最新问答

更多

您如何使用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?)

将diff文件复制到存储库的根目录,然后执行以下操作: git apply yourcoworkers.diff 有关apply命令的更多信息, apply 见其手册页 。 顺便说一下:一个更好的方法是通过文件交换整个提交文件是发送者上的命令git format-patch ,然后在接收器上加上git am ,因为它也传送作者信息和提交信息。 如果修补程序应用程序失败,并且生成diff的提交实际上在您的备份中,则可以使用尝试在更改中合并的apply程序的-3选项。 它还适用于Unix管道,如下

将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)

尝试将第二行更改为snprintf(buf1, sizeof buf1, "%.2f", balance1); 。 另外,为什么要声明用该特定表达式分配缓冲区的存储量? EDIT @LưuVĩnhPhúc在下面的评论中提到我的原始答案中的格式说明符将舍入而不是截断,因此根据如何在不使用C舍入的情况下截断小数,您可以执行以下操作: float balance = 200.56866; int tmp = balance1 * 100; float balance1 = tmp / 100.0; c

OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)

这是简单的解决方案 在你需要写的控制器中 BackendMenu::setContext('Archetypics.Team', 'website', 'team'); 请参阅https://octobercms.com/docs/backend/controllers-views-ajax#navigation-context BackendMenu::setContext('Author.Plugin name', 'Menu code', 'Sub menu code'); 你需要在r

页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)

每当发出请求时ASP都会创建一个新的Page对象,并且一旦它将响应发送回用户就不会保留对该Page对象的引用,因此只要你找不到某种方法来保持生命自己引用该Page对象后,一旦发送响应, Page和只能通过该页面访问的所有对象才有资格进行垃圾回收。 ASP creates a new Page object whenever a request is made, and it does not hold onto the reference to that Page object once it

codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)

要在生产服务器中调试这个,你可以临时放 error_reporting(E_ALL); 并查看有哪些其他错误阻止正确的重定向。 您还应该检查生产服务器发送的响应标头。 它是否具有“缓存”,是否需要重新验证标头等 to debug this in production server, you can temporary put error_reporting(E_ALL); and see what other errors are there that prevents the proper

在计算机拍照在哪里进入

打开娥的电脑.在下面找到视频设备点击进去就可以了...

使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)

你是对的。 第一次输入后,换行符将保留在输入缓冲区中。 第一次读取后尝试插入: cin.ignore(); // to ignore the newline character 或者更好的是: //discards all input in the standard input stream up to and including the first newline. cin.ignore(numeric_limits::max(), '\n'); 您必须为#inc

No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)

for (int k = 0; k > 10; k++) { System.out.println(k); } k不大于10,所以循环将永远不会执行。 我想要什么是k<10 ,不是吗? for (int k = 0; k < 10; k++) { System.out.println(k); } for (int k = 0; k > 10; k++) { System.out.println(k); } k is not greater than 10, so loop

单页应用程序:页面重新加载(Single Page Application: page reload)

优点是不注销会避免惹恼用户,以至于他们会想要杀死你:-)。 说真的,如果每次刷新页面时应用程序都会将我注销(或者在新选项卡中打开一个链接),我再也不会使用该应用程序了。 好吧,不要这样做。 确保身份验证令牌存储在刷新后的某个位置,即不在某些JS变量中,而是存储在cookie或本地存储中。 The advantage is that not logging off will avoid pissing off your users so much that they'll want to kill

在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)

EXECUTE IMMEDIATE 'SELECT '||field_val_temp ||' FROM tableb WHERE function_id = :func_val AND rec_key = :rec_key' INTO field_val USING 'STDCUSAC' , yu.rec_key; 和, EXECUTE IMMEDIATE 'UPDATE tablec SET field_val_'||i||' = :field_val' USI