Forum Discussion

cheungj's avatar
cheungj
Visitor
12 years ago

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?

4 Replies

  • 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
  • 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
  • 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