I am developing an android application in which i have to parse the url in json format.Url is
http://search.yaho开发者_Go百科oapis.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 this article. 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();
}
}
精彩评论