Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call a json webservice through android

I need to access a .Net web service in Rest format using JSON. I m pretty new to this concept and very much confused about how this works.... Any one who can give an overview of this. I need the steps that I need to follow to use JSON. Right now my doubt is how to use JSON to grab to output.

like image 271
Neetesh Avatar asked Aug 16 '11 10:08

Neetesh


1 Answers

This is the simplest way to parse Json web servie

    String str="url";
    try{
        URL url=new URL(str);
        URLConnection urlc=url.openConnection();
        BufferedReader bfr=new BufferedReader(new InputStreamReader(urlc.getInputStream()));
        String line;
        while((line=bfr.readLine())!=null)
        {
        JSONArray jsa=new JSONArray(line);
        for(int i=0;i<jsa.length();i++)
           {
           JSONObject jo=(JSONObject)jsa.get(i);
                        title=jo.getString("deal_title");  //tag name "deal_title",will return value that we save in title string
                    des=jo.getString("deal_description");
       }
    }
    catch(Exeption e){
    }

Mention Internet permission in android manifest

like image 195
Tofeeq Ahmad Avatar answered Oct 21 '22 07:10

Tofeeq Ahmad