iphone - Send Nested JSON using AFNetworking -


to send registration data server, using json in following form:

{"regdata": {  "city":"some city",  "country":"some country",  "email_id":"abc@gmail.com",  "mobilenumber":"+00xxxxxxxxxx",  "username":"name of user"  } } 

here how sending.

 nsurl * url = [[nsurl alloc] initwithstring:registerurlstring];             afhttpclient * httpclient = [[afhttpclient alloc] initwithbaseurl:url];             httpclient.parameterencoding = afjsonparameterencoding;             [[afnetworkactivityindicatormanager sharedmanager] setenabled:yes];             nsdictionary * params = @{@"regdata": @{                                               @"city": self.cityfield.text,                                               @"country": self.countryfield.text,                                               @"email_id": self.emailfield.text,                                               @"mobilenumber": self.numberfield.text,                                               @"username": self.username.text,                                               }                                       };              nsmutableurlrequest * request = [httpclient requestwithmethod:@"post" path:registerurlstring parameters:params];             afhttprequestoperation * operation = [afjsonrequestoperation jsonrequestoperationwithrequest:request success:^(nsurlrequest *request, nshttpurlresponse *response, id json) {                 nslog(@"success: %@", json);              } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error, id json) {             nslog(@"error: %@", [error debugdescription]);             }];              [operation start]; 

but unfortunately getting error:

error domain=nscocoaerrordomain code=3840 "the operation couldn’t completed. (cocoa error 3840.)" (json text did not start array or object , option allow fragments not set.) userinfo=0x94b3c30 {nsdebugdescription=json text did not start array or object , option allow fragments not set.}

your request fine. error error domain=nscocoaerrordomain code=3840 being returned because server responding invalid json object. nslog operation.responsestring see what's being sent back.


Comments

Popular posts from this blog

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -