【问题标题】:Load JSON From External Storage从外部存储加载 JSON
【发布时间】:2020-02-21 08:50:23
【问题描述】:

我正在为 LG 智能电视构建应用。插入智能电视时,我需要从 USB 驱动器加载 json 数据。

我不知道该怎么做,从来没有在这样的应用上工作过。 我的问题是如何访问外部存储并将 json 数据加载到我的应用程序中?

【问题讨论】:

    标签: webos


    【解决方案1】:

    使用 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);
                    }
    
    

    USB 的文件路径是 file://usb:[INDEX]/[FILE_PATH] [INDEX] 是 USB 索引(可以连接多个 USB)。

    更多帮助可以在这里找到:http://webossignage.developer.lge.com/api/scap-api/scap16/storage/?wos_flag=readFile#readFile

    您可以使用getStorageInfo() 来检查您的USB 是否可用。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-28
      • 2013-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-21
      相关资源
      最近更新 更多