ios - Adding Parameters to setHTTPBody request Xcode -


i having trouble adding parameters line of code. have created global variable can access variable , have nslog's verify accessible i'm having troubling adding variable.

my line of code , add tran_id has been defined variable "ttt" nsstring. way have in code right not working.

 nslog(@"tran id: %@", ttt);  [request sethttpbody:[@"{\n  \"partner_key\": \"vxykmw3n8e\",\n  \"auth_token\": \"qau9qcfz6xe7airrbge0wz4p6e01gebl\",\n  \"tran_id\": \"%@\"\n}", ttt datausingencoding:nsutf8stringencoding]]; 

i don't think can set params in sethttpbody method, need have nsstringwithformat before:

nsstring *body = [nsstring stringwithformat:@"{\n  \"partner_key\": \"vxykmw3n8e\",\n  \"auth_token\": \"qau9qcfz6xe7airrbge0wz4p6e01gebl\",\n  \"tran_id\": \"%@\"\n}", ttt];  [request sethttpbody:[body datausingencoding:nsutf8stringencoding]]; 

of course, quick-n-dirty method - because sending json data, consider learning how nsjsonserialization works.


Comments