【问题标题】:How to get JSON values using variable in brightscript如何使用 Brightscript 中的变量获取 JSON 值
【发布时间】:2015-08-23 23:42:58
【问题描述】:

我正在尝试使用一个变量来表示该值来解析这个 JSON,但它不起作用。我不知道是因为变量不代表字符串还是我不能做我想做的事情。

Function get_categoriesItems(category As Object) As Object

request = CreateObject("roUrlTransfer")
port = CreateObject("roMessagePort")
request.SetMessagePort(port)
request.SetUrl("http://jrocca.com/sample1.json")
if (request.AsyncGetToString())
while (true)
msg = wait(0, port)
if (type(msg) = "roUrlEvent")
code = msg.GetResponseCode()
if (code = 200)
playlist = CreateObject("roArray", 10, true)
print "";msg.GetString()
json = ParseJSON(msg.GetString())
print "";category
for each video in json.category
topic = {
Title: video.Title
Image: video.Image
Url: video.Url
}
playlist.push(topic)
print "";playlist
end for
return playlist
endif
else if (event = invalid)
request.AsyncCancel()
endif
end while
endif
return invalid

End Function

我能做些什么来解决这个问题?

【问题讨论】:

    标签: json eclipse eclipse-plugin roku brightscript


    【解决方案1】:

    问题出在for each video in json.category 行。将其替换为for each video in json.lookup(category)。这使用了roAssociativeArrayLookup(key as String) as Dynamic 函数。

    【讨论】:

      猜你喜欢
      • 2023-03-30
      • 2016-05-01
      • 1970-01-01
      • 2020-09-02
      • 2021-08-05
      • 2017-10-12
      • 2018-06-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多