itunes JSON request in iOS returns an XML object -


i want access information itunes within ios app.

i doing regular http request (sending parameters both post or directly in url)

the url works, because if use browser, expected result (in json format).

{ "resultcount":0, "results": [] }

but within ios, jsonobjectwithdata returns null object.

after inspecting data object, found object returned xml object (that not contain required info, instead bunch of xml keys/values]

nsdata *data = [nsdata datawithcontentsofurl:[nsurl urlwithstring:@"http://itunes.apple.com/search"]];  nserror *directerror; nsdictionary *jsondict = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&directerror];  if (!directerror) {     nslog(@"%@", jsondict);  } else {     nslog(@"json error: %@", directerror.localizeddescription);         } 

i looked possible post parameter force response json, didn't find anything.

attached sample of info contained in data object (after xml parsing):

menus

key title

key music

string url

key https://itunes.apple.com/webobjects/mzstore.woa/wa/viewgenre?id=34

string items

key title

key free on itunes

string url

regards... enrique

update: encourage not use nsdata datawithurl method fetching contents since triggers request in synchronous manner. if requesting lot of data freeze ui thread. fetching should use asynchronous operations.

i using following code , returns json response later converted json object shown below:

-(void) setup {     nsstring *itunesurl = @"https://itunes.apple.com/search?term=pink-floyd";      nsurlsession *session = [nsurlsession sharedsession];     [[session datataskwithurl:[nsurl urlwithstring:itunesurl] completionhandler:^(nsdata *data, nsurlresponse *response, nserror *error) {          id jsonobject = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingallowfragments error:nil];          nslog(@"success");      }] resume]; } 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -