嗯,我正在使用這個庫來解析xml:SwiftyXMLParser,但不幸的是無法從IOS中得到響應結果數組,但我可以在瀏覽器see this link或sample of respond上看到它們!無法從URL解析XML確實API
這是我的操作:
URLSession.shared.dataTask(with: NSURL(string: urlString)! as 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"] also didn't work
}
}).resume()
這是我在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 is array but No results!!
<\results>
因此,沒有人知道這是爲什麼?如何?
謝謝。
我嘗試使用JSON:
讓indeedAPI =「api.indeed.com/ads/apisearch?publisher=4935138002921571 & Q =(SEARCHTERM)&格式= JSON & L =%2C + TX &排序= &半徑= 50 & ST = & JT = &開始= &限制= 10 &清爽= &濾波器= &經緯度= 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" : [
// also no results
],
"totalResults" : 0,
"version" : 2,
"end" : 0,
"pageNumber" : 0,
"start" : 0,
"query" : "ios developer",
"highlight" : true
}
@Rob謝謝你,我已經添加了我的輸出 –
@Rob對不起再次,我已經編輯我的問題。謝謝 –
'xml [「結果」]'甚至可以工作嗎? – Larme