I removed html from the php file as suggested by Kostya Vasilyev and
changed the approach to retrieve the information. The new Android code
is as follows:

========================
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
                BufferedReader in = null;
                try {
                        HttpClient client = new DefaultHttpClient();
                        HttpGet request = new HttpGet();
                        request.setURI(new URI("http://www.onyoursixinc.com/
grabitgood.php"));
                        HttpResponse response = client.execute(request);
                        in = new BufferedReader (new
InputStreamReader(response.getEntity().getContent()));
                        StringBuffer sb = new StringBuffer("");
                        String line = "";
                        String NL = System.getProperty("line.separator");
                        while ((line = in.readLine()) != null) {
                                sb.append(line + NL);
                        }
                        in.close();

                        String page = sb.toString();
                        System.out.println(page);
                        } catch (URISyntaxException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (ClientProtocolException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } catch (IOException e) {
                                        // TODO Auto-generated catch block
                                        e.printStackTrace();
                                } finally {
                                if (in != null) {
                                        try {
                                                in.close();
                                        } catch (IOException e) {
                                                e.printStackTrace();
                                        }
                                }
                        }


                //parse json data
        try{
                JSONArray jArray = new JSONArray(result);
                for(int i=0;i<jArray.length();i++){
                        JSONObject json_data =
jArray.getJSONObject(i);
 
Log.i("log_tag","org_id:"+json_data.getInt("id")+
                                ", orgname:
"+json_data.getString("orgname")+
                                ", orgcity:
"+json_data.getString("orgcity")+
                                ",
orgstate:"+json_data.getString("orgstate")
                        );
                }
        }catch(JSONException e){
                Log.e("log_tag", "Error parsing data "+e.toString());
        }


    }
=====================
from my LOGCAT I can see I am getting the correct select response but
it looks like I am now picking up the html tags from the connect.php
file ince I use
require ("connect.php");  The LOGCAT now shows me the following:

================
10-12 17:37:41.320: INFO/System.out(218): <html><head><title>Find
Organizations</title></head><body style="background-
color:#33990f"><body>
10-12 17:37:41.330: INFO/System.out(218):
[{"org_id":"39575","orgname":"ARTHRITIS FOUNDATION - VIRGINIA
CHAPTER","orgcity":"RICHMOND","orgstate":"VA"}]
10-12 17:37:41.350: ERROR/log_tag(218): Error parsing data
org.json.JSONException: A JSONArray text must start with '[' at
character 0 of
10-12 17:37:42.042: INFO/ActivityManager(53): Displayed activity
com.oys.gfa.acecapper/.SelectOrgs: 40958 ms (total 40958 ms)

I am getting closer but still "no cigar". I don't know how to get rid
of all the HTML since I will actually need to have the user enter a
city and state and then "down select" from the response. The php file
I am using is a hard coded SELECT since I figured dealing with JSON
would be the more difficult problem to tackle.

Thanks,
Capt Spaghetti


On Oct 12, 3:57 pm, Mark Murphy <mmur...@commonsware.com> wrote:
> On Tue, Oct 12, 2010 at 3:51 PM, Capt Spaghetti <gene_august...@msn.com> 
> wrote:
> >                HttpPost httppost = new HttpPost("graborginfo.php");
>
> That is not a valid URL.
>
>
>
>
>
> >                HttpResponse response = httpclient.execute(httppost);
> >                HttpEntity entity = response.getEntity();
> >                InputStream is = entity.getContent();
> >        }catch(Exception e){
> >                Log.e("log_tag", "Error in http connection
> > "+e.toString());
> >        }
> >        //convert response to string
> >        try{
> >                        InputStreamReader is = new 
> > InputStreamReader(System.in);
> >                BufferedReader reader = new BufferedReader(is);
> >                StringBuilder sb = new StringBuilder();
> >                String line = null;
> >                while ((line = reader.readLine()) != null) {
> >                        sb.append(line + "\n");
> >                }
> >                is.close();
>
> >                result=sb.toString();
> >        }catch(Exception e){
> >                Log.e("log_tag", "Error converting result
> > "+e.toString());
> >        }
>
> For this, I recommend using the BasicResponseHandler pattern:
>
> http://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpc...
>
> (orhttp://bit.ly/lCVgZif that URL is too long)
>
> > The LOGCAT output for the error is as follows:
> > =====================
> > 10-12 11:14:08.199: INFO/global(233): Default buffer size used in
> > BufferedReader constructor. It would be better to be explicit if an 8k-
> > char buffer is required.
> > 10-12 11:14:20.460: ERROR/log_tag(233): Error parsing data
> > org.json.JSONException: A JSONArray text must start with '[' at
> > character 0 of
>
> You may want to dump the value you are trying to parse as JSON to
> LogCat, as it is not what you think it is.
>
> --
> Mark Murphy (a Commons 
> Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy
>
> Android 2.2 Programming Books:http://commonsware.com/books- Hide quoted text -
>
> - Show quoted text -

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

Reply via email to