Egret之JSZip基础
首先要整第三方库 , 在上一篇中已经有所介绍 , 这里不讲。
关于 jszip和AS的aszip差不多一样。
这里我写了三个文件 : a.txt , b.xml , c.json 打包到一个 ziptest.zip的压缩包中。
a.txt:
b.xml:
c.json:
ziptest.zip的位置:
核心代码 :::
privateloadZip():void{RES.getResByUrl("resource/ziptest.zip",function(data):void{letzipj:JSZip=newJSZip(data);this.analysisJSZip(zipj);},this,RES.ResourceItem.TYPE_BIN);}privateanalysisJSZip(zipj:JSZip):void{//a.txt解析lettxtstr:JSZipObject=zipj.file("ziptest/a.txt");console.log('Txtcontentis'+txtstr.asText());//b.xml解析letxmlstr:JSZipObject=zipj.file("ziptest/b.xml");letxmlConfig:egret.XML=egret.XML.parse(xmlstr.asText());console.log("thexmlrootnameis:"+xmlConfig.name);letxmlChileren:Array<egret.XMLNode>=xmlConfig.children;letxmlChildrenLen:number=xmlChileren.length;letxmlCell:egret.XML=null;for(leti:number=0;i<xmlChildrenLen;i++){xmlCell=<egret.XML><any>xmlChileren[i];if(xmlCell.name=="role"){letxmlName:egret.XML=<egret.XML><any>xmlCell.children[0];//获得<namestr="Aonaufly"/>console.log("xmlrolenameis:"+xmlName["$str"]);break;}}//c.json解析letjsonstr:JSZipObject=zipj.file("ziptest/c.json");letjsonc:any=JSON.parse(jsonstr.asText());console.log("jsonnameis:"+jsonc.name);}
关于 zipj.file("ziptest/a.txt");
结果:
遍历Zip中的文件名
const$zip:JSZip=newJSZip(xmlData);const$files:object=$zip["files"];for(varkeyin$files){console.log(key);//键名}
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。