ios - JSON outputted as key with blank value -
ios - JSON outputted as key with blank value -
so have dictionary i'm trying send node hapi server ios device.
and reason request payload adding dictionary key blank value. here ios code
nsdictionary *userdata = [user usertodictionary: newuserinfo]; nsdata *userjson = [nsjsonserialization datawithjsonobject: userdata options: kniloptions error: nil]; nsstring *urlstring = [nsstring stringwithformat: @"%@%@/addnewuser", kbaseurl, kusers]; // set url nsurl *url = [nsurl urlwithstring: urlstring]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl: url]; [request sethttpmethod: @"post"]; [request addvalue: @"application/json" forhttpheaderfield: @"content-type"]; // set url session nsurlsessionconfiguration* config = [nsurlsessionconfiguration defaultsessionconfiguration]; nsurlsession *session = [nsurlsession sessionwithconfiguration: config]; nsurlsessionuploadtask *uploadtask = [session uploadtaskwithrequest: request fromdata: userjson completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) { if(error) { } else { } }]; [uploadtask resume];
and here payload
{ '{"userlastnamekey":"kwon7","useremailkey":"email7","userfirstnamekey":"michael7","userusernamekey":"username7","userpasswordkey":"password7"}': '' }
can help me this? don't want save user info in mongo key. seems weird.
posting reply though op has solved problem , explained wrong. said headers. had exact same problem , solution content-type
header. since passing json object rest client, figured took care of setting right content-type
, not.
content-type: application/json
hapi not assume request payload json. json.stringify(request.payload, null, 2);
shows same format problem in question. must specify content-type
hapi.js correctly parse json payload json.
ios json node.js hapijs
Comments
Post a Comment