如何在brightscript中存储roAssociativeArray的通道?

时间:2016-05-16 23:47:06

标签: roku brightscript

这是存储收藏夹频道列表的功能。但是我无法将数组存储在注册表中,因为只能将字符串作为输入

 Function addToFavorites(channeljson as object)as boolean
        print "started"
        sec = CreateObject("roRegistrySection", "FuturV1")
        poster = CreateObject("roAssociativeArray")
        'if not sec.Exists("FavoriteChannels")
        contentList = CreateObject("roArray", 100, true)
        'else

        'end if 
       poster.ShortDescriptionLine1 = channeljson.name
       poster.SDPosterURL = channeljson.logo
       poster.HDPosterURL = ch`enter code here`anneljson.logo
       poster.url= channeljson.ch
       contentList.push( poster ) `enter code here`
       'sec.Write("FavoriteChannels", ba.ToAsciiString())

       print "again"
       print contentList.GetEntry(0) 
    end function

3 个答案:

答案 0 :(得分:2)

最简单的方法是使用 formatJSON()/ parseJSON()

答案 1 :(得分:1)

将任何对象存储到持久存储 -

  1. 将Object(roArray或roAssociativeArray)转换为String
  2. 将该字符串存储在持久存储中。
  3. 从持久性存储中检索数据 -

    1. 从持久性中读取字符串。
    2. 将String转换为Object以供使用。您可以在roAssociativeArray的情况下使用ParseJSON函数。

答案 2 :(得分:1)

这是使用ParseJSON和FormatJSON保存注册表设置的函数示例:

Sub SaveSettings(settings as Object)
    SaveRegistryString("Settings", FormatJSON({settings: settings}, 1))
End Sub

Function LoadSettings() as Dynamic
    json = GetRegistryString("Settings")
    if json <> ""
        obj = ParseJSON(json)
        if obj <> invalid
            return obj.settings
        end if
    end if
    return invalid
End Function

Function GetRegistryString(key as String, default = "") As String
    sec = CreateObject("roRegistrySection", "YourAppName")
    if sec.Exists(key)
        return sec.Read(key)
    end if
    return default
End Function

Sub SaveRegistryString(key As String, value As String)
    sec = CreateObject("roRegistrySection", "YourAppName")
    sec.Write(key, value)
    sec.Flush()
End Sub