Page 302 -
P. 302

what to do?


           Define your app’s requirements


           Let’s think a little bit about what your Android app needs to do.




             Nothing’s really
           changed...you just
           have to get the web
           data onto the phone.



                                                 Frank: Well…first off, the view code no longer has to generate HTML,
                                                  so that makes things interesting.
                                                 Jill: In fact, you need the web server only to supply your data on
                                                 request, not all that generated HTML.
                                                 Joe: Ah ha! I’ve solved it. Just send the pickle with all the data from the
                                                  server to the Android phone. It can’t be all that hard, can it?

                                                 Jill: Sorry, guys, that’ll cause problems. The pickle format used by
                                                 Python 3 is incompatible with Python 2. You’ll certainly be able to send
                                                 the pickle to the phone, but the phone’s Python won’t be able to work
                                                 with the data in the pickle.

                                                 Frank: Darn…what are our options, then? Plain data?
             Frank                     Joe
                         Jill                    Joe: Hey, good idea: just send the data as one big string and parse it on
                                                 the phone. Sounds like a workable solution, right?

                                                 Jill: No, that’s a potential disaster, because you never know in what
                                                 format that stringed data will arrive. You need an data interchange format,
                                                  something like XML or JSON.

                                                 Frank: Hmm…I’ve heard XML is a hound to work with…and it’s
                                                 probably overkill for this simple app. What’s the deal with JSON?
                                                 Joe: Yes, of course, I keep hearing about JSON. I think they use it in
                                                 lots of different places on the Web, especially with AJAX.
                                                 Frank: Oh, dear…pickle, XML, JSON, and now AJAX…I think my
                                                 brain might just explode here.
                                                 Jill: Never worry, you only need to know JSON. In fact, you don’t even
                                                 need to worry about understanding JSON at all; you just need to know
                                                 how to use it. And, guess what? JSON comes standard with Python
                                                 2 and with Python 3…and the format is compatible. So, we can use
                                                 JSON on the web server and on the phone.
                                                 Frank & Joe: Bonus! That’s the type of technology we like!


           266    Chapter 8
   297   298   299   300   301   302   303   304   305   306   307