Flex读取外部XML中文乱码解决办法(转)
方法一:
用URLLoader加载XML,然后将data转化为ByteArray
用byteArray.readMultiByte(bytes.length,"utf-8")
然后将转化后的字符串再强制转化为XML
?
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.Binary;
var urlRequest:URLRequest = new URLRequest(source);
loader.addEventListener("complete",completeHandler);
loader.load(urlRequest);
private var completeHandler(evt:Event):void
{
? ? ?var bytes:ByteArray = ByteArray(evt.currentTarget.data);
? ? ?var xmlStr:String = bytes.readMultiByte(bytes.length,"utf-8");
? ? ?var xml:XML = XML(xmlStr);
? ? ?trace(xml);
}