gpt4 book ai didi

Android JSONArray 循环

转载 作者:太空宇宙 更新时间:2023-11-03 11:50:00 26 4
gpt4 key购买 nike

这是我从网络服务得到的结果

"year":["2014","2013","2012","2011","2010","2009","2008","2007","2006","2005","2004","2003","2002","2001","2000","1999","1998","1997","1996","1995","1994","1993","1992","1991","1990","1989","1988","1987","1986","1985","1984","1983","1982","1981","1980","1979","1978","1977","1976","1975","1974","1973","1972","1971","1970","1969","1968","1967","1966","1965","1964","1963","1962","1961","1960","1959","1958","1957","1956","1955","1954","1953","1952","1951","1950","1949","1948","1941","1940","1938","1933","1928"]

我想在 Activity 中循环播放并显示 list 。所以我写了以下内容

JSONArray ar=obj.getJSONArray("year");
for(i=0;i<ar.length();i++){
// How to get the value of the item in array
// Tried ar[i]
}

我的疑问是如何获取数组中项目的值?我需要这样的 list 2014,2013,2012....

请给我一个主意谢谢

最佳答案

试试这个..

你可以得到像ar.getString(i)

JSONArray ar=obj.getJSONArray("year");
for(i=0;i<ar.length();i++){
Log.v("Result--",""+ar.getString(i));
}

关于Android JSONArray 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21845734/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com