Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

json android: How to read the online json format

$
0
0

I am new to android. I have a url which only has the json format. Suppose the url is- http://www.example.com/filter... This url contains only json format data. Take for example this link contains following material: - [ {u:"user",s:"male" image:"hello.jpg"}] The link contains only the above data. Now, I want to test the connection in my android i.e.whether i am able to connect to the values of parameter u. I created a http client and tried to parse the json format. The program but does not display anything.. Here's what i did

HttpClient httpclient = new DefaultHttpClient();    HttpPost httppost = new HttpPost("http://www.example.com/filter");    try    {        HttpResponse response = httpclient.execute(httppost);        InputStream in = response.getEntity().getContent();byte [] buffer = new byte[in.available()];        while (in.read(buffer) != -1);        String jsontext = new String(buffer);        JSONArray entries = new JSONArray(jsontext);for (i=0;i<entries.length();i++)        {            JSONObject post = entries.getJSONObject(i);            if(post.getString("u")=="driver")            {            x="Success";            }        }        txtResult.setText(x); // x is string    }

I just want to test my connection. Please help!


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>