All,

Again, I'm new to all of this but fell I'm making some headway with Java and Android. So, I am using the code below to call a php program on my webserver that performs a check and returns a JSON object.

*try {
            // Construct data
String data = "code=" + imei + "&installtype=" + installType + "&apikey=" + GlobalVars.GCapiKey + "&platform=" + GlobalVars.platform;

            // Send data
            URL url = new URL("http://myserver/initialize.php?"; + data);
            URLConnection conn = url.openConnection();

            // Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));

            retInit = rd.readLine();
        //    wr.close();
            rd.close();
        } catch (Exception e) {
        }*

An example of the JSON object is as follows:

{ "errcode":0, "errdesc":"Initialized", "expiredate":"2011/03/23"}
{"errcode":1, "errdesc":"Sorry but you do not have a valid API key. Please contact Support to get one."}

So, I can see that retInit is getting this return string, but is there an easy way of breaking down this JSON object so that I can check (for example) the value or errcode ?

Also, is there a way to check the return status of URLConnection conn = url.openConnection(); ? I'd use this to ensure I was able to get a good connection.

Appreciate any help on this. Again, I am coming from WebOS and Mojo had these kind of things pretty much built in.


--
------------------------------------------------------------------------

David Williams
Check out our WebOS mobile phone app for the Palm Pre and Pixi:
<http://www.dtw-consulting.com/GolfCaddie> Golf Caddie <http://www.dtw-consulting.com/GolfCaddie> | Golf Caddie Forum <http://www.dtw-consulting.com/GolfCaddie/forum> | Golf Caddie FAQ <http://www.dtw-consulting.com/GolfCaddie/faq.html> by DTW-Consulting, Inc.


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

<<inline: GClogo.png>>

Reply via email to