Parsing JSON from PubNub
All responses from the subscribe service are structured as follows:
An array, containing:
An array of new messages since the last call to subscribe
A new time token to use for the next call
The first time you make a request to subscribe, you get something like this:
[[],"13782280489181338"]
This is a JSON array. The first is an array of messages—for the first request, it will be empty. The second entry is a string, and it is the new time token to use.
After the first request, you'll see something that looks more like this:
[[ "Some message here", "Another message here" ], "13782280489181345"]
Now, the first entry isn't full. It's an array of strings (in fact, these are JSON data which means they can hold any data you want, but in the case of our chat application we are sending string values). These are all of the new messages which have been published to the channel since the last time you subscribed.
To parse this, we'll use a JSON parser made for Unity called SimpleJSON...