ios - Unable to parse XML from URL for indeed API -


well, using library parse xml: swiftyxmlparser unfortunately unable results array respond in ios can see them on browser see link or sample of respond!

this operation :

urlsession.shared.datatask(with: nsurl(string: urlstring)! url, completionhandler: { (data, response, error) -> void in      if error != nil {         print(error)         return     }     if let data = data {         let xml = xml.parse(data)         print(xml)         //tried xml["results"]["0"] didn't work     }  }).resume() 

this output in ios :

<response version="2"> <query>ios</query> <location>austin, tx</location> <clickedcategories/> <paginationpayload/> <radius>25</radius> <dupefilter>true</dupefilter> <highlight>false</highlight> <start>1</start> <end>10</end> <pagenumber>0</pagenumber> <totalresults>315</totalresults> <results> //this array no results!! <\results> 

so knows why? , how?

thank you.

my attempt json:

let indeedapi = "api.indeed.com/ads/apisearch?publisher=4935138002921571&q=(searchterm)&format=json&l=%2c+tx&sort=&radius=50&st=&jt=&start=&limit=10&fromage=&filter=&latlong=1&co=&chnl=&userip=1.2.3.4&v=2"

    let googleyoutubeapiurl = url(string: indeedapi.addingpercentencoding(withallowedcharacters: characterset.urlqueryallowed)!)      let request:urlrequest = urlrequest(url: googleyoutubeapiurl!, cachepolicy: nsurlrequest.cachepolicy.reloadignoringcachedata, timeoutinterval: 5.0)      operationqueue.main.cancelalloperations()     let task = urlsession.shared.datatask(with: request, completionhandler: { data, response, error in          if let _ = error {             print(error.debugdescription)             return         }          if let data = data {             completion(json(data: data))         } else { print("data nil"); return }      })     task.resume()  {   "paginationpayload" : "",   "location" : "%2c tx",   "dupefilter" : true,   "results" : [ // no results   ],   "totalresults" : 0,   "version" : 2,   "end" : 0,   "pagenumber" : 0,   "start" : 0,   "query" : "ios developer",   "highlight" : true } 

if you're looking result entries, can like:

let xml = xml.parse(data)  guard xml.error == nil else {     print("\(xml.error!)")     return }  let results = xml["response", "results"]  guard results.error == nil && results["result"].error == nil else {     print("no results")     return }  result in results["result"] {     if let jobtitle = result["jobtitle"].text {         print("\(jobtitle)")     } } 

Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -