ios - Passing array on Webservices -


i developing 1 app,in have used send contact numbers server through webservices.here contact numbers array,and send contact array through webservices.here below code,

nsstring *myrequeststring1 = [[nsstring alloc] initwithformat:@"contact_numbers=%@",mobiilearray ];   nsdata *myrequestdata = [ nsdata datawithbytes: [ myrequeststring1 utf8string ] length: [ myrequeststring1 length ] ]; nsmutableurlrequest *request = [ [ nsmutableurlrequest alloc ] initwithurl: [ nsurl urlwithstring:@"http://myproject.in/myproject-contacts.php"]];  [request sethttpmethod: @"post"]; [request setvalue:@"application/x-www-form-urlencoded" forhttpheaderfield:@"content-type"]; [request sethttpbody: myrequestdata]; nsurlresponse *response; nserror *err; nsdata *returndata = [nsurlconnection sendsynchronousrequest: request returningresponse:&response error:&err]; nserror* error; nsmutablearray* result = [nsjsonserialization jsonobjectwithdata:returndata                                                          options:kniloptions                                                             error:&error]; nslog(@"result: %@", result); 

but response null ,any mistakes on code? can please suggest me thank you.

try below solution..!

replace lines of code

nsstring *myrequeststring1 = [[nsstring alloc] initwithformat:@"contact_numbers=%@",mobiilearray ]; nsdata *myrequestdata = [ nsdata datawithbytes: [ myrequeststring1 utf8string ] length: [ myrequeststring1 length ] ]; 

//with lines of code

//nsdictionary *dict = [nsdictionary dictionarywithobject: mobiilearray forkey:@"contact_numbers"];  nsstring* myrequeststring1 = [mobiilearray jsonrepresentation]; nsdata *myrequestdata = [myrequeststring1 datausingencoding:nsutf8stringencoding]; 

//put

[request setvalue:@"application/json" forhttpheaderfield:@"content-type"]; 

check it...


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -