objective c - Passing json to request body using restkit in ios -


i using restkit in application post /get webservice. having nested json want post request body of api. have used following code pass json request body of service when run application returns null in request body.

this nested json want pass request body

{     amount =     {         currency = inr;         value = 1;     };     merchantaccesskey = udnirnirfbnrirn;     merchanttxnid = sssscdcdcdedff;     notifyurl = "";     paymenttoken =     {         paymentmode =         {             cvv = 968;             expiry = “11/20”;             holder = axis;             number = xxxxxxxxxxxx;             scheme = asxsc;             type = debit;         };         type = paymentoptiontoken;     };     requestsignature = abgd9456fef7b3f9023232734706;     returnurl = "https://www.example.com/";     userdetails =     {         address =         {             city = "";             country = "";             state = "";             street1 = "";             street2 = "";             zip = "";         };         email = “abc@gmail.com”;         firstname = abc;         lastname = xyz;         mobileno = 1234567890;     }; } 

this code sending json api.

- (void)complexrequestmapping{  rkobjectmapping* paymentamount = [rkobjectmapping requestmapping];    rkobjectmapping* amountmapping =       [rkobjectmapping mappingforclass:[amount class]];   [amountmapping addattributemappingsfromdictionary:                      @{@"currency" : @"currency", @"value" : @"value"}];   [paymentamount       addpropertymapping:[rkrelationshipmapping                              relationshipmappingfromkeypath:@"amount"                                                   tokeypath:@"amount"                                                 withmapping:amountmapping]];    rkobjectmapping* userdetailsmapping =       [rkobjectmapping mappingforclass:[userdetails class]];   [userdetailsmapping       addattributemappingsfromdictionary:@{                                            @"email" : @"email",                                            @"firstname" : @"firstname",                                            @"lastname" : @"lastname",                                            @"mobileno" : @"mobileno"                                          }];   rkobjectmapping* addressmapping =       [rkobjectmapping mappingforclass:[useraddress class]];   [addressmapping addattributemappingsfromdictionary:@{                                                        @"city" : @"city",                                                        @"country" : @"country",                                                        @"state" : @"state",                                                        @"street1" : @"street1",                                                        @"street2" : @"street2",                                                        @"zip" : @"zip"                                                      }];   [addressmapping       addpropertymapping:           [rkrelationshipmapping               relationshipmappingfromkeypath:@"address"                                    tokeypath:@"address"                                  withmapping:[userdetailsmapping                                                      inversemapping]]];    rkobjectmapping* paymenttokenmapping =       [rkobjectmapping mappingforclass:[ctspaymenttoken class]];   [paymenttokenmapping addattributemappingsfromdictionary:@{@"type" : @"type"}];    rkobjectmapping* paymentoptionsmapping =       [rkobjectmapping mappingforclass:[ctspaymentoption class]];   [paymentoptionsmapping       addattributemappingsfromdictionary:@{                                            @"cvv" : @"cvv",                                            @"expiry" : @"expiry",                                            @"holder" : @"holder",                                            @"number" : @"number",                                            @"scheme" : @"scheme",                                            @"type" : @"type"                                          }];   [paymentoptionsmapping       addpropertymapping:           [rkrelationshipmapping               relationshipmappingfromkeypath:@"paymentmode"                                    tokeypath:@"paymentmode"                                  withmapping:[paymenttokenmapping                                                      inversemapping]]];   rkrequestdescriptor* requestdes = [rkrequestdescriptor       requestdescriptorwithmapping:amountmapping                        objectclass:[ctspaymentrequest class]                        rootkeypath:nil                             method:rkrequestmethodpost];   [objectmanager addrequestdescriptor:requestdes];  } 

try simple json  {    title = test;    body = sample text;    auther = test author; } // using nsjson class can convert json data object.here manually create own object      yourobject *object = [yourobject new];     object.title = @“test”;     object.body = @“sample text”;     object.author = @“test auther”;      rkresponsedescriptor * yourobjectdescriptor = [rkresponsedescriptor responsedescriptorwithmapping:responsemapping method:rkrequestmethodany pathpattern:@"/test" keypath:@"test" statuscodes:statuscodes];     rkobjectmapping *requestmapping = [rkobjectmapping requestmapping];     [requestmapping addattributemappingsfromarray:@[@"title", @"author", @"body"]];      rkrequestdescriptor *requestdescriptor = [rkrequestdescriptor requestdescriptorwithmapping:requestmapping objectclass:[yourobject class] rootkeypath:@“test” method:rkrequestmethodany];      rkobjectmanager *manager = [rkobjectmanager managerwithbaseurl:base_url];     [manager addrequestdescriptor:requestdescriptor];      // post create     [manager postobject:object path:@“/test” parameters:nil success:nil failure:nil]; 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -