I am trying to parse this JSON using a variable to represent the value, but it isn't working. I don't know if it is because the variable isnt representing the string or if I just can't do what I am trying to do.
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
What can I do to solve this?
The problem is in the line for each video in json.category
. Replace it with for each video in json.lookup(category)
. This uses the Lookup(key as String) as Dynamic
function of roAssociativeArray.