Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Phonegap,ios文件阅读器不工作_Ios_Html_Cordova_Filereader - Fatal编程技术网

Phonegap,ios文件阅读器不工作

Phonegap,ios文件阅读器不工作,ios,html,cordova,filereader,Ios,Html,Cordova,Filereader,此代码是xml到json的解析代码。我正在跟踪phonegap引用。但是我的文件阅读器没有改变stateReady。这始终是状态0。请帮帮我。。 filereader.result方法在phonegap中不起作用? 我想回家。我会一直看到这篇文章。好吧,你可能已经解决了它,但如果对其他人有用,你的回调链接不正确,就用这一行更改你的行 var xml2; function onLoad() { document.addEventListener("deviceready", onDevi

此代码是xml到json的解析代码。我正在跟踪phonegap引用。但是我的文件阅读器没有改变stateReady。这始终是状态0。请帮帮我。。 filereader.result方法在phonegap中不起作用?
我想回家。我会一直看到这篇文章。

好吧,你可能已经解决了它,但如果对其他人有用,你的回调链接不正确,就用这一行更改你的行

var xml2;

function onLoad() {
    document.addEventListener("deviceready", onDeviceReady, false);
}

function onDeviceReady() {
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
}

function gotFS(fileSystem){
    fileSystem.root.getFile("ccw.xml", null, gotFile, fail);
}

function gotFileEntry(fileEntry) {
    fileEntry.file(gotFile, fail);
}

function gotFile(file) {
    readAsText(file);
}

function readAsText(file) {

    var reader = new FileReader();

    reader.readAsText(file);    

    reader.onload = function(){
    };

    xml2 = reader.result;

    writeJson();

}

function fail(evt) {
    console.log(evt.target.error.code);
}

function parseXml(xml) {

    var dom = null;

    if (window.DOMParser) {
        try {
            dom = (new DOMParser()).parseFromString(xml, "text/xml");
        }
        catch (e) { dom = null; }
    }
    else if (window.ActiveXObject) {
        try {
            dom = new ActiveXObject('Microsoft.XMLDOM');

            dom.async = false;

            if (!dom.loadXML(xml)) // parse error ..
          window.alert(dom.parseError.reason + dom.parseError.srcText);
        }
        catch (e) { dom = null; }
    }
    else
       alert("oops");

   return dom;
}

function writeJson(){

    var json;

    //    for(var i = 0 ; i < xml.length ; i++) {
    show("\n\n" + (json = xml2json(parseXml(xml2), "  ")) + "\n\n");
    //        console.log("====="+i+"/"+xml.lenght+"=====");
    //    }
}

function show(s) { 

    document.getElementById("out").innerHTML += (s+"\n").replace(/&/g, "&amp;").replace (/</g,"&lt;").replace(/>/g,"&gt;").replace(/\n/g, "<br/>") + "<hr/>";
}


试试看,这也有助于添加控制台日志消息,以便您更容易调试和了解发生的情况以及顺序。

应用程序是否调用OnDeviceReady?您可以通过在OnDeviceReady事件中放置一个简单警报来测试它。
fileSystem.root.getFile("ccw.xml", null, gotFile, fail);
fileSystem.root.getFile("ccw.xml", null, gotFileEntry, fail`);