Load JSON From External Storage

不问归期 提交于 2020-01-16 08:36:12

问题


I am building an app for an LG Smart TV. I need to load json data from a USB drive when it's inserted into the smart TV.

I'm not sure how to do this, never worked on an app like this. My question is how do I gain access to external storage and load json data into my app?


回答1:


Using the SCAP API (v1.2+)

                function readFile() {
                    var successCb = function (cbObject) {
                        var data_text = cbObject.data;
                        // do something with the json string
                    };

                    var failureCb = function (cbObject) {
                        var errorCode = cbObject.errorCode;
                        var errorText = cbObject.errorText;
                        // do something with the error
                    };

                    // Read the whole file from the beginning, as a text file.
                    var options = {
                        path: "file://usb:[INDEX]/[FILE_PATH]",
                        position: 0,
                        encoding: 'utf8'
                    };

                    var storage = new Storage();
                    storage.readFile(successCb, failureCb, options);
                }

The filepath for a usb is file://usb:[INDEX]/[FILE_PATH] [INDEX] is the usb index (could have multiple USBs connected).

Additional help can be found here: http://webossignage.developer.lge.com/api/scap-api/scap16/storage/?wos_flag=readFile#readFile

You can use getStorageInfo() to check if your usb is available.



来源:https://stackoverflow.com/questions/58551101/load-json-from-external-storage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!