O'Reilly logo

Unity Multiplayer Games by Alan Stagner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required