0

简而言之:我的 xml 字符串编码错误。但是在使用 NSLog 并从 Xcode 控制台复制字符串之后,字符串得到了正确的编码。

完整解释:

我使用 ASIFormDataRequest 和编码将 xml 字符串发送到服务器:

<?xml version="1.0" encoding="UTF-8"?>

我收到错误 500“服务器无法解析您的 xml”。我想,这是我的 xml 中的一个错误。我试图分析,我从 NSArray 和 NSDictionary 的字符串中构建了 xml。这些字符串取自先前的服务器响应和文本字段。

但后来我用了NSLog("%@", myXmlString). 我在 Xcode 控制台中看到了我的 xml 字符串。我从控制台复制了字符串并直接粘贴到代码中,然后将此处理后的字符串发送到服务器。并且没有错误。

问题:如何以与 Xcode 控制台更改字符串相同的方式更改字符串(字符串编码)?

更新

来自 NSLog 控制台的字符串:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>&lt;item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>

我使用wireshark来获取字符串服务器。这里是:

<?xml version="1.0" encoding="UTF-8"?><env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns0="http://com.test/types/AstoriaObjectProperties" xmlns:ns1="http://com.test/wsdl/AstoriaObjectProperties" xmlns:ns2="http://java.sun.com/jax-rpc-ri/internal"><env:Body><ns1:setObjectProperties env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><HashMap_1 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID1"/></item></HashMap_1><HashMap_2 xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[2]"><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">id</key><value xsi:type="xsd:string">0000001aWGA2070GYZ</value></item><item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">annotations</key><value href="#ID2"/></item></HashMap_2></ns1:setObjectProperties><ns0:ArrayOfhashMap id="ID1" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap><ns0:ArrayOfhashMap id="ID2" env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="enc:Array" enc:arrayType="ns2:hashMap[1]"><item xsi:type="ns2:hashMap" enc:arrayType="ns2:mapEntry[7]">...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationUser$$$</key><value xsi:type="xsd:string">AstoriaAdmin</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status</key><value xsi:type="xsd:string">waiting for decision</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationID$$$</key><value xsi:type="xsd:string">00000043X951EE3073607F44F7D00000000000000951FF3076D000000590000003C647C7668696D696B2D6163733A433A5C50726F6772616D2046696C65735C4173746F72696120536F6674776172655C434D535C64617461626173655C63616231303030302E64627C31347C367C3263307C31303030303E00704B585000000000YZ</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Comment</key><value xsi:type="xsd:string">comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationDate$$$</key><value xsi:type="enc:dateTime">2012-09-18T10:22:40.000Z</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">Annotation Status Comment</key><value xsi:type="xsd:string">status comment</value></item>...<item xsi:type="ns2:mapEntry"><key xsi:type="xsd:string">$$$XD_AnnotationName$$$</key><value xsi:type="xsd:string">Legal Review</value></item></item></ns0:ArrayOfhashMap></env:Body></env:Envelope>

所以,我在这个 xml 中看到了额外的点。

4

0 回答 0