Test that JSON received is valid
Posted: Fri May 18, 2018 5:15 am
I'm working on an app that reads JSON from a web service. For this I'm using JSONImport, putting the JSON into a LC array and from the array into an SQLite db. It seems to work nicely. Then I thought "I really should code this so that it doesn't explode if the web service passes it invalid JSON". So to see what would happen if the app received invalid JSON I:
- wrote the working JSON that I received from the web service into a file; then
- chopped the final "}" off the JSON (to make it incorrect); then
- had JSONImport read the file containing the incorrect JSON.
The IDE stops dead with an "LCB Error in file json.lcb at line 65: syntax error: 1:2734 unexpected end of input" error.
Is there an easy way for me to test that JSON is valid before I pass it to JSONImport?
Ultimately my app will need to run on Windows desktop + Android + IOS. I've seen a few forum posts about an IsJSON function in a fastJSON library. Is that the way to go? I was hoping to be able to keep using JSONImport as it seems to do the job fine when it does receive valid JSON.
Thanks in advance
Kim
LC9 on Windows 10
- wrote the working JSON that I received from the web service into a file; then
- chopped the final "}" off the JSON (to make it incorrect); then
- had JSONImport read the file containing the incorrect JSON.
The IDE stops dead with an "LCB Error in file json.lcb at line 65: syntax error: 1:2734 unexpected end of input" error.
Is there an easy way for me to test that JSON is valid before I pass it to JSONImport?
Ultimately my app will need to run on Windows desktop + Android + IOS. I've seen a few forum posts about an IsJSON function in a fastJSON library. Is that the way to go? I was hoping to be able to keep using JSONImport as it seems to do the job fine when it does receive valid JSON.
Thanks in advance
Kim
LC9 on Windows 10