简体   繁体   中英

Parsing a url in json format in android application

I am developing an android application in which i have to parse the url in json format.Url is

http://search.yahooapis.com/NewsSearchService/V1/newsSearch?appid=YahooDemo&output=json

I have tried by making json format object and then passing values.Has anyone implemented it before,If yes can he help me?

Thanks in advance Tushar

catch the "Error" element like JSONObject, not JSONArray.

You can use GSON. Take a look at thisarticle . You parse it like this:

public void runJSONParser(){
        try{
        Log.i("MY INFO", "Json Parser started..");
        Gson gson = new Gson();
        Reader r = new InputStreamReader(getJSONData("http://search.twitter.com/trends.json"));
        Log.i("MY INFO", r.toString());
        TwitterTrends objs = gson.fromJson(r, TwitterTrends.class);
        Log.i("MY INFO", ""+objs.getTrends().size());
        for(TwitterTrend tr : objs.getTrends()){
            Log.i("TRENDS", tr.getName() + " - " + tr.getUrl());
        }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM