ios - AFNetworking Send JSON as a parameter for POST request -


i gone several answers same question...but unable figure out issue..i getting error

* terminating app due uncaught exception 'nsinvalidargumentexception', reason: '* +[nsjsonserialization datawithjsonobject:options:error:]: invalid top-level type in json write'

my code is:

nsdictionary *logindict=[[nsdictionary alloc] initwithobjectsandkeys:password.text,@"password",username.text,@"username",nil]; nserror *error; nsdata *jsondata = [nsjsonserialization datawithjsonobject:logindict                                                           options:nsjsonwritingprettyprinted                                                              error:&error]; if (jsondata) {         nsstring *jsonstring = [[nsstring alloc] initwithdata:jsondata encoding:nsutf8stringencoding]; } else {         nslog(@"got error: %@", error); }    afhttprequestoperationmanager *manager = [afhttprequestoperationmanager manager];  manager.requestserializer = [afjsonrequestserializer serializer];  [manager.requestserializer settimeoutinterval:20];  [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"accept"];  [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"content-type"];  manager.responseserializer = [afjsonresponseserializer serializer];  manager.responseserializer = [afjsonresponseserializer serializerwithreadingoptions:nsjsonreadingallowfragments];  [manager post:baseurllogin parameters:jsonstring          success:^(afhttprequestoperation *operation, id responseobject) {         nslog(@"json: %@", responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) {         nslog(@"error: %@", error); }]; 

try this

directly pass logindict in call , check

manager.requestserializer = [afjsonrequestserializer serializer]; /* [manager.requestserializer settimeoutinterval:20]; [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"accept"]; [manager.requestserializer setvalue:@"application/json" forhttpheaderfield:@"content-type"];  manager.responseserializer = [afjsonresponseserializer serializer];  manager.responseserializer = [afjsonresponseserializer serializerwithreadingoptions:nsjsonreadingallowfragments];  */ [manager post:baseurllogin parameters: logindict      success:^(afhttprequestoperation *operation, id responseobject) {     nslog(@"json: %@", responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) {     nslog(@"error: %@", error); }]; 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -