Monday, 15 September 2014

iphone - JSON serialisation in AFNewtorking is failing -



iphone - JSON serialisation in AFNewtorking is failing -

i trying perform requests returns json string web-service using afnetworking receiving next error afnetworking 1.3.3

@"json text did not start array or object , alternative allow fragments not set."

and here json valid json string , used many online validators create sure

"{\"errorcode\":0,\"vercode\":\"8595\"}"

afnetworking code not working

nsstring *urlstring = [base_url stringbyappendingstring:paramseters]; afhttpclient *httpclient = [[afhttpclient alloc] initwithbaseurl:[nsurl urlwithstring:base_url]]; nsmutableurlrequest *request = [httpclient requestwithmethod:@"get" path:urlstring parameters:nil]; afjsonrequestoperation *operation = [afjsonrequestoperation jsonrequestoperationwithrequest:request success:^(nsurlrequest *request, nshttpurlresponse *response, id json) { nsdictionary *jsondic = (nsdictionary *)json; success(jsondic); } failure:^(nsurlrequest *request, nshttpurlresponse *response, nserror *error, id json) { cperror *cperror = [cperror cperrorwitherrorcode:error.code errordesc:error.localizeddescription]; failure(cperror); }]; [operation start];

i able parse json nsdictionary using below code want able utilize afnetworking in order create utilize of it's built in features , there way create afnetworking understands json string ?

nsurl *url = [nsurl urlwithstring:@"http://103.1.173.60/ims-mobile-wcf/mobilewcf.svc/addupdatemobileclient/123123/443da4444/1/1"]; nsmutableurlrequest *request = [nsmutableurlrequest requestwithurl:url cachepolicy:nsurlrequestreloadignoringlocalandremotecachedata timeoutinterval:120]; [request sethttpmethod:@"get"]; [nsurlconnection sendasynchronousrequest:request queue:[nsoperationqueue mainqueue] completionhandler:^(nsurlresponse *response, nsdata *data, nserror *connectionerror) { nslog(@"%@",connectionerror); nserror *error = nil; nsstring *jsonstring = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments error:&error]; nsdictionary *jsondictionary = [nsjsonserialization jsonobjectwithdata: [jsonstring datausingencoding:nsutf8stringencoding] options: nsjsonreadingmutablecontainers error: &error]; }];

try:

afjsonrequestoperation *operation = ... operation.jsonreadingoptions = nsjsonreadingallowfragments; [operation start];

iphone objective-c json ios7 afnetworking

No comments:

Post a Comment