2011-12-01, 09:54
el_Paraguayo Wrote:Montellesse,This has actually come up several times before, the recommended method is to "count the brackets" or in the case of json count the brackets and the quote marks. To simplify there should be an equal number of opening and closing brackets that aren't surrounded with quote marks (e.g. inside a string). In TU we do this by keeping a count, increasing the count on an opening bracket, decreasing it on a closing one and doing nothing in between quotes. One special case to remember to account for is when you start partway through a notification you need to check if your count has become negative, reset the count and assume you are at the start of the next message. The only other case that can cause problems is starting inside a string, and if anyone has any ideas how to detect this it would be most helpful; in general this is unlikely to happen.
I'm writing a python script that's trying to catch the "OnStop" notification (by listening on port 9090).
While I can search the data for "OnStop", a neater way would be to detect the end of the notification and then parse the full JSON response.
However, I'm having difficulty in making the script determine the end of the notification as there doesn't seem to be any break character (maybe this is intentional - i.e. as required by the specification).
Do you have any tips for catching the end of the notification?
Thanks,
el_P