- Sverre Tvedt
- PowerBuilder
- Tuesday, 9 April 2019 02:06 PM UTC
(PB 2017 R3 build 1858 / Windows 10 )
From an httpclient object I receive JSON strings that I need to parse. They may be quite complicated with deeply nested structures.
My first problem is to parse NULL values.
My preliminary code looks like this:
ls_result = ij_parser.loadstring(as_json)
ll_root = ij_parser.getrootitem( )
//
...
this.ErrorDetails = ij_parser.getitemstring(ll_root,"ErrorDetails")
this.ErrorMessage= ij_parser.getitemstring(ll_root,"ErrorMessage")
this.Successful= ij_parser.getitemboolean(ll_root,"Successful")
...
and so on for the various elements. I know the expected datatypes, of course.
However, there may be a null or more in the dataset, like this:
"Successful":true,"ErrorMessage":null,"ErrorDetails":null
This code causes runtime exceptions, rather than returning null strings. Why? Buggy parser? I would have expected null strings to be returned.
To avoid it I have to wrap every getitem in aTRY-CATCH block , and do a setnull in the catch part. Yikes.
Is there a better way without going completely low-level?
Find Questions by Tag
Helpful?
If a reply or comment is helpful for you, please don’t hesitate to click the Helpful button. This action is further confirmation of their invaluable contribution to the Appeon Community.