Hi
I’m trying to use SOME data that can be retrieved online from a base64 encoded JSON
a little confused because yesterday a version of this seemed to have worked and now it does not
as such I took a snapshot of the data that doesn’t work and stored as a gist (to have a repeatable test)
I KNOW I wont be able to render the international characters and will live with it (for now)
but the base64 decode seems to have SOME issue (is it the non-ascii, or overall size - I dont know)
Using online base64 test tool (https://www.base64decode.org/) & JSON validateion tools (https://jsonformatter.curiousconcept.com/)
I surmize that the data itself is actually fine. I even took a decoded version
and served it up to this roku test (bypassing the base64 decode)
and ParseJSON() didnt seem to have any issues with the international characters
Function test()
request = CreateObject("roUrlTransfer")
request.SetCertificatesFile("common:/certs/ca-bundle.crt")
request.AddHeader("X-Roku-Reserved-Dev-Id", "")
request.InitClientCertificates()
request.SetUrl("https://gist.githubusercontent.com/quartern/c4bb656c005ded4b3c3bead99dd5b71a/raw/e35ae64009457d050e24cbdf0ebf22fc8d4aecd8/gistfile1.txt")
tmpfile="tmp:/quartern_resp.txt"
request.GetToFile(tmpfile)
ba = CreateObject("roByteArray")
if not ba.ReadFile(tmpfile)
print "ReadFile failed"
else if ba.count() < 1
print "Empty response"
else
' we know we get these with quotes - strip them
txt=ba.ToAsciiString()
print "B4 STRIP >>>"+txt.left(10)+"..."+txt.right(10)+"<<<"
ba.pop()
ba.shift()
txt=ba.ToAsciiString()
print "AFTER STRIP >>>"+txt.left(10)+"..."+txt.right(10)+"<<<, count=",ba.count()
' decode and parse
ba.FromBase64String(ba.ToAsciiString())
txt=ba.ToAsciiString()
print "AFTER DECODE >>>"+txt.left(10)+"..."+txt.right(10)+"<<<, count=",ba.count()
theData=ParseJSON(ba.ToAsciiString())
endif
DeleteFile(tmpfile)
theData.x=1 ' just force debugger on fail
return theData
end Function
Here is the relevant output in the debugger:
B4 STRIP >>>"eyJ3Y2ZJc...lNiI6W119"<<<
AFTER STRIP >>>eyJ3Y2ZJcC...xlNiI6W119<<<, count= 271071
AFTER DECODE >>>{"wcfIp":[...??? ??? ??<<<, count= 203301
BRIGHTSCRIPT: ERROR: ParseJSON: Unterminated string: ...
The size ration seems reasonable but the end of that decoded string should be something like> ,“Table6”:}
so the question marks do not make sense
Are there any size or character limitations on the base64 encoded data?
Thanks
–QuarterN
