We’re writing an app that communicates with an internet-based CMS in JSON. Unfortunately, some types of network connection e.g. through public Wifi have a web gateway that they require you to go through before you can use the net normally. This means we are trying to JSON parse an HTML webpage. I would expect it to throw an exception stating that the HTML isn’t well-formed JSON but instead it tries to parse it, runs out of memory and collapses.
I have looked through the Android JSON functions and can’t find a function that simply tells you if a string is JSON or not. Is there such a function? If not, am I simply going to have to write something heuristic to trap obviously non-JSON strings?
Something like: