Parsing Bundles to json

3 views
Skip to first unread message

Will Pearson

unread,
Jun 16, 2011, 12:27:19 PM6/16/11
to openla...@googlegroups.com
I've found a nice way of doing this using the gson library.

http://code.google.com/p/google-gson/

Meaning I've wasted a bit of time trying to do it the hard way. I have
learnt more about introspection.

It needs a bit of introspection or reflection (I forget the difference
between the two) to get the mMap field which is normally private

Without all the error handling a function to do this looks roughly like

import com.google.gson.*;
// And some other stuff

String IntenttoJson (Intent i)
{
Gson g = new Gson();
Field mMapField;
mMapField = Bundle.class.getDeclaredField("mMap");
mMapField.setAccessible(true);
return ( g.toJson(mMapField.get(i.getExtras() )));
}

I can make a class for this if you want Tom? But it would probably be
as easy to include this snippet.

So now you should be able to add crap to Intents then easily send it
over to the server without caring what it is.

Will

tom

unread,
Jun 27, 2011, 6:21:59 AM6/27/11
to OpenLaserTag
this is interesting:

http://blog.davidsingleton.org/mobiletcp



Its recommending UDP streams instead of TCP streams for mobile
applications

Will Pearson

unread,
Jun 27, 2011, 12:09:18 PM6/27/11
to openla...@googlegroups.com
On 27 June 2011 11:21, tom <bollo...@gmail.com> wrote:
> this is interesting:
>
> http://blog.davidsingleton.org/mobiletcp
>
>
>
> Its recommending UDP streams instead of TCP streams for mobile
> applications
>
>

Saw this. Hmm.

I'd probably go for UDP for updating on going game state, which we
don't care about losing much. Although we should probably do the final
game state updates over TCP so that we don't have to worry about how
to do the guaranteed reception.

Might have to think about not using Tornado and going back to twistd.
Or going threaded and having a TCP and an UDP server updating the same
database.

Or maybe erlang so no one has a clue about the code :P It would be
great for large scale tracking of people using the code for the
Command and Conquer game mode.

Will

Reply all
Reply to author
Forward
0 new messages