objective c - Yahoo stock symbol suggest lookup is not json format! Unable to parse -


my purpose make app (ios) user can enter combination of letters , yahoo suggest several stocks come closet match search.

my question related older question, here: stock ticker symbol lookup api

and answered doing this: http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=k&callback=yahoo.finance.symbolsuggest.sscallback

you this:

yahoo.finance.symbolsuggest.sscallback({"resultset":{"query":"k","result":[{"symbol":"k","name":"kellogg company","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"ko","name":"the coca-cola company","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"kra","name":"kraton performance polymers inc.","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"kmi","name":"kinder morgan, inc.","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"key","name":"keycorp.","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"kmb","name":"kimberly-clark corporation","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"krft","name":"kraft foods group, inc.","exch":"nms","type":"s","exchdisp":"nasdaq","typedisp":"equity"},{"symbol":"kors","name":"michael kors holdings limited","exch":"nyq","type":"s","exchdisp":"nyse","typedisp":"equity"},{"symbol":"gmcr","name":"keurig green mountain, inc.","exch":"nms","type":"s","exchdisp":"nasdaq","typedisp":"equity"},{"symbol":"klac","name":"kla-tencor corporation","exch":"nms","type":"s","exchdisp":"nasdaq","typedisp":"equity"}]}})

but not valid json format. first part of returned data is:

yahoo.finance.symbolsuggest.sscallback(

and don't know that. when this:

nsdictionary *root = [nsjsonserialization jsonobjectwithdata: data options:nsjsonreadingallowfragments error: &parsingerror]; nslog(@"root: %@", root); 

the root null. in normal json object use options:kniloptions changed after trying google solutions.

the error message this:

error domain=nscocoaerrordomain code=3840 "the operation couldn’t completed. (cocoa error 3840.)" (invalid value around character 0.) userinfo=0x7ff5637375f0 {nsdebugdescription=invalid value around character 0.}

what should do? please explicit. i've googled mad, don't understand. thank you!

my full code is:

- (void)createsearchobj: (nsstring*)searchstr {  nsstring *searchstring = [nsstring stringwithformat: @"http://d.yimg.com/autoc.finance.yahoo.com/autoc?query=%@&callback=yahoo.finance.symbolsuggest.sscallback", searchstr];  nslog(@"searchstring: %@", searchstring);  nsurl                *url     = [nsurl urlwithstring:searchstring]; nsurlrequest         *request = [nsurlrequest requestwithurl:url]; nsurlsession         *session = [nsurlsession sharedsession]; nsurlsessiondatatask *task    = [session datataskwithrequest:request completionhandler:^                                  (nsdata *data, nsurlresponse *response, nserror *error)                                  {                                      nslog(@"error: %@", error);                                      nslog(@"data: %@", data);                                       nserror *parsingerror = error;  /*                                      nsdictionary *root =                                      [nsjsonserialization jsonobjectwithdata:                                       data options:kniloptions error: &parsingerror]; */                                      nsdictionary *root =                                      [nsjsonserialization jsonobjectwithdata:                                       data options:nsjsonreadingallowfragments error: &parsingerror];                                       nslog(@"root: %@", root);                                       if (!parsingerror) {                                          dispatch_async(dispatch_get_main_queue(), ^{                                              nsdictionary *dict = [root objectforkey:@"resultset"];                                             nslog(@"dict: %@", dict);                                          });                                       } else {                                           nslog(@"could not parse json: %@", parsingerror);                                       }                                   }];  [task resume]; [self.view endediting:yes];  } 

looks yahoo putting out jsonp (json padding). sadly solutions seem "take substring of whatever's inside parentheses , parse that."

how parse jsonp in objective-c?


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -