我的json以XML [{...}] string>开头我怎么解析它我尝试过很多东西什么都行不通

时间:2022-11-26 02:07:26

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

结果就像这一开始的XML,我可以使用代码删除XML部分,感谢帮助它已经4周了,我在网上找不到类似的案例

我的json以XML  [{...}]  string>开头我怎么解析它我尝试过很多东西什么都行不通

3 个解决方案

#1


0  

try this XML/HTML parser: Fuzi

试试这个XML / HTML解析器: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)
        }
    }

#2


0  

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

这不是json的回应。它xml响应。你不能通过json序列化解析这个。

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

您需要一个XML解析器来解析此响应。有关更多信息,请参阅本教

#3


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.

实际上响应中的XML格式取代了JSON,因此您需要解析第一个XML(NSXMLParser,RaptureXML,AFXMLParserResponseSerializer),然后您获得的对象将是您需要的JSON字符串。

#1


0  

try this XML/HTML parser: Fuzi

试试这个XML / HTML解析器: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)
        }
    }

#2


0  

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

这不是json的回应。它xml响应。你不能通过json序列化解析这个。

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

您需要一个XML解析器来解析此响应。有关更多信息,请参阅本教

#3


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.

实际上响应中的XML格式取代了JSON,因此您需要解析第一个XML(NSXMLParser,RaptureXML,AFXMLParserResponseSerializer),然后您获得的对象将是您需要的JSON字符串。