I am new in IOS and i want convert some mix data(xml and JSON mix data ) receive from SOAP web service into array using swift 3. i receive this data in a string variable in parser method.
func connection(_ connection: NSURLConnection, didFailWithError error: Error){
print("\(error)")
print("Some error in your Connection. Please try again.")
let alert = UIAlertController(title: "Error", message: "No internet connection", preferredStyle: UIAlertControllerStyle.alert)
// add an action (button)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
self.present(alert, animated: true, completion: nil)
}
func connectionDidFinishLoading(_ connection: NSURLConnection){
print("Received \(UInt(webResponseData.count)) Bytes")
// let theXML = String(webResponseData.mutableBytes, length: webResponseData.length, encoding: String.Encoding.utf8)
let theXML = XMLParser(data: webResponseData)
theXML.delegate = self
theXML.parse()
print("\(theXML)")
}
func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String, qualifiedName qName: String, attributes attributeDict: [AnyHashable: Any]){
currentElement = elementName
// print(currentElement)
}
func parser(_ parser: XMLParser, foundCharacters string: String){
currentElement = string
UserDefaults.standard.set(currentElement, forKey: "string")
//print(currentElement)
// arr.append(currentElement)
}
func parser(_ parser: XMLParser,didEndElement elementName: String, namespaceURI: String?,qualifiedName qName: String?){
let sessionelement = UserDefaults.standard.object(forKey: "string")
print(sessionelement!)
}
here is response from from web service:
[{"Id":2,"imgName":"_U11tmp1464839741959976567.jpg","SeqNo":1},
{"Id":1,"imgName":"_U11tmp1464839741959976567.jpg","SeqNo":2},
{"Id":3,"imgName":"_U11tmpIMG-14117-WA59976567.jpg","SeqNo":3}]
JSONresponse, where is theXMLpart? And what is your question, it seems like you are already doing the parsing?JSONresponse is stored, so I made an assumption, tell me if it's something else and i will update my answer.