0

The result come like this start with XML, Can I remove the XML part using code, thanks for helping it is been 4 weeks now I couldn't find a similar case online

Image

Cœur
  • 37,241
  • 25
  • 195
  • 267
killvak
  • 96
  • 8

3 Answers3

0

This is not json response. It xml reponse. You can't parse this by json serialization.

You need a XML parser to parse this response. For more see this tutorial.

Jamil
  • 2,977
  • 1
  • 13
  • 23
  • ya but this tutorial is for object C not swift and i'm still a beginner , but i appreciate your help thx ^^ – killvak Nov 08 '15 at 11:54
0

Actually XML format in the response supersedes JSON, so you will need to parse first XML (NSXMLParser, RaptureXML, AFXMLParserResponseSerializer) and then the object you obtain will be JSON string which you need.

Eugene Dudnyk
  • 5,553
  • 1
  • 23
  • 48
0

try this XML/HTML parser: Fuzi

import Fuzi

Alamofire.request(.GET, url)
    .responseString { response in
        do {
            let doc = try XMLDocument(string: response.result.value)
            if let root = doc.root {
                 // this should be the content within the <string></string> element
                print(root.stringValue)
            }
        } catch let error {
            print(error)
        }
    }
cezheng
  • 564
  • 4
  • 10
  • Thx alot it did work and now i have the JSON with out the XML but how cab i display it i tried: let jsson = root.stringValue print(jsson) let json = JSON(jsson) let name = json[0]["FromEmirateNameAr"].stringValue print(name) : – killvak Nov 08 '15 at 07:59
  • what json library are you using though? I recommend you take a look at this one: https://github.com/SwiftyJSON/SwiftyJSON – cezheng Nov 08 '15 at 08:03
  • and tried .string instead of .stringValue it gived null , also i tried let json =JSON(root.stringValue) if let jsonArray = json.array{ for item in jsonArray { if let jsonDict = item.dictionary //jsonDict : [String : JSON]? { let postId = jsonDict["FromEmirateNameAr"]!.intValue let text = jsonDict["FromRegionNameAr"]!.stringValue print(postId) print(text) } } } // and i can't access to the data inside of for sorry for asking again thanks for your help ^^ – killvak Nov 08 '15 at 08:14
  • i'm using SwiftyJson when i tried : let jsson = root.stringValue print(jsson) json = JSON(data: jsson) // it made an error ((data: String)' is not convertible to '(data: NSData, options: NSJSONReadingOptions, error: NSErrorPointer)) ( Cannot assign a value of type 'String' to a value of type 'NSData') – killvak Nov 08 '15 at 08:25
  • Json(data:) takes an NSData param I guess. Convert the string into NSData then do it again – cezheng Nov 08 '15 at 09:03
  • still can't get it i will keep trying tho do u know anyway to do so ? sorry i keep asking u :P – killvak Nov 08 '15 at 12:29
  • make use of google, you can find out many of these answers yourself http://stackoverflow.com/questions/24039868/creating-nsdata-from-nsstring-in-swift – cezheng Nov 08 '15 at 12:47
  • sorry for bothering you but i did search but i'm still new at this sorry again for bothering u ^^ – killvak Nov 08 '15 at 13:07