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 ...

Get Unity Multiplayer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.