Roku Developer Program

Join our online forum to talk to Roku developers and fellow channel creators. Ask questions, share tips with the community, and find helpful resources.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
cheungj
Visitor

ParseJson does not handle negative numbers

Has anyone encountered an issue where the parsejson method when it parses out a Json integer that is a negative value it forces it as a positive value? so for example i have this json string

{test: -1} but when i run the parse json on it the value of test = 1 instead of -1?
0 Kudos
4 REPLIES 4
RokuMarkn
Visitor

Re: ParseJson does not handle negative numbers

This seems to show that it works. Can you post code where it doesn't work?


BrightScript Debugger> s="{"+chr(34)+"test"+chr(34)+": -1}"
BrightScript Debugger> ?s
{"test": -1}
BrightScript Debugger> j= ParseJSON(s)
BrightScript Debugger> ?j
test: -1


--Mark
0 Kudos
cheungj
Visitor

Re: ParseJson does not handle negative numbers

jsonString = "{" + Chr(34) + "test" + Chr(34) + ":" + Stri(-1).trim() + "}"
print jsonString

print Stri(ParseJson(jsonString).test)

the first print out works and displays the right json with the negative value but after I parse and get the attribute test from the json array it returns as 1
0 Kudos
RokuMarkn
Visitor

Re: ParseJson does not handle negative numbers

This works for me. What firmware version are you running?

--Mark


BrightScript Debugger> jsonString = "{" + Chr(34) + "test" + Chr(34) + ":" + Stri(-1).trim() + "}"
BrightScript Debugger> ?jsonString
{"test":-1}
BrightScript Debugger> print Stri(ParseJson(jsonString).test)
-1
0 Kudos
cheungj
Visitor

Re: ParseJson does not handle negative numbers

5.1 in any case I did a workaround for it
0 Kudos
Need Assistance?
Welcome to the Roku Community! Feel free to search our Community for answers or post your question to get help.

Become a Roku Streaming Expert!

Share your expertise, help fellow streamers, and unlock exclusive rewards as part of the Roku Community. Learn more.