Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/36.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
向服务器iphone发出请求时如何将数组作为参数传递_Iphone_Nsurlrequest - Fatal编程技术网

向服务器iphone发出请求时如何将数组作为参数传递

向服务器iphone发出请求时如何将数组作为参数传递,iphone,nsurlrequest,Iphone,Nsurlrequest,给定的: a chunk of books and each book will associated with unique id user can order more than one book For example, user A will choose 3 books whose id are a, b ,c. How can I send an array containing with these id in the request so that server c

给定的

a chunk of books and each book will associated with unique id
user can order more than one book
  For example, user A will choose 3 books whose id are a, b ,c. How can I send an array 
  containing with these id in the request so that server can know that user A are ordering these books
场景

a chunk of books and each book will associated with unique id
user can order more than one book
  For example, user A will choose 3 books whose id are a, b ,c. How can I send an array 
  containing with these id in the request so that server can know that user A are ordering these books
目标

   making an NSMutableURLRequest and send this request to server and let server know which books 
    are being picked 
问题

a chunk of books and each book will associated with unique id
user can order more than one book
  For example, user A will choose 3 books whose id are a, b ,c. How can I send an array 
  containing with these id in the request so that server can know that user A are ordering these books

取决于服务器期望的格式,例如,如果使用RESTful,则必须在post或get和基于该生成查询之间进行选择。如果确实使用restful,则使用RestKit API并使用params属性。(或者您可以直接使用基本的ios api构建它们)。您也可以使用JSON格式发送数据,但服务器必须知道如何解析数据。

取决于服务器期望的格式,例如,如果您使用RESTful,则必须在post或get之间进行选择,并基于该格式生成查询。如果确实使用restful,则使用RestKit API并使用params属性。(或者您可以直接使用基本的ios api构建它们)。您也可以以JSON格式发送数据,但服务器必须知道如何解析数据。

JSON将足够了。JSON将足够了。我们正在使用Restfull,这是post请求。服务器端希望我将一组books'id作为参数之一传递。我正在使用AFNetworking API向服务器发送请求。但是我仍然被困在如何向他们发送id数组的问题上……你不能发送“数组”本身,如果服务器需要JSON格式,那么你首先将数组转换为JSON,然后将其作为键“books”的值发送。(JSON只是一种格式,它是一组服务器可以读取和解析的文本,以构建自己的数组)我们正在使用Restfull,这是post请求。服务器端希望我将一组books'id作为参数之一传递。我正在使用AFNetworking API向服务器发送请求。但是我仍然被困在如何向他们发送id数组的问题上……你不能发送“数组”本身,如果服务器需要JSON格式,那么你首先将数组转换为JSON,然后将其作为键“books”的值发送。(JSON只是一种格式,它是服务器可以读取和解析的一组文本,以构建自己的数组)