For循环迭代Array中的JSON对象

时间:2016-01-21 13:22:38

标签: java android json for-loop retrofit

我如何get and show JSON's Object's value Arraylearning所有JSON "learning": [ { "code":"2K14 - 2", "os":"Windows - 2" }, { "code":"2K15 - 2", "os":"Linux - 2" }, { "code":"2K16 - 2", "os":"Mac - 2" } ] List<Learning> learning = value.getLearning(); for(Learning m : learning) { // I guess, here I am missing something, which is really useful String code = m.getCode(); String os = m.getOs(); viewHolder.learning.setText("Code: "+code+" OS: "+os); }

以下是execute数组的样子:

getting

代码

Code: 2k16, OS: Mac - 2

当我want to get我的计划时,this这个:

Code: 2k14 OS: Windows - 2,  Code: 2k15 OS: Linux - 2, Code: 2k16 OS: Mac - 2

#wrapper { overflow: hidden; width: 100%; max-width: 900px; margin: 0 auto; border: 1px solid #c5c5c5; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; background: #eee; } #outer { width: 20%; padding-bottom: 20%; color: #FFF; position: relative; float: left; overflow: hidden; display: inline-block; } #inner { position: absolute; left: 0px; right: 0px; top: 0px; bottom: 0px; background: #66F; padding: 10px; -webkit-transition: all .3s ease; -moz-transition: all .3s ease; -ms-transition: all .3s ease; -o-transition: all .3s ease; transition: all .3s ease; } #inner:hover { transform: scale(1.1); -ms-transform: scale(1.1); /* IE 9 */ -moz-transform: scale(1.1); /* Firefox */ -webkit-transform: scale(1.1); /* Safari and Chrome */ -o-transform: scale(1.1); /* Opera */ vertical-align: middle; }之类的内容<div id="wrapper"> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> <div id="outer"> <div id="inner"> test </div> </div> </div>

NULL

3 个答案:

答案 0 :(得分:2)

如果想要以单TextView显示所有数据,请执行此操作:

viewHolder.learning.append("Code: "+code+" OS: "+os + ", ");

使用TextView.append代替TextView.setText

答案 1 :(得分:1)

您可以发布您的Retrofit界面以及与之相关的所有模型类吗?

然后你会有这样的东西来阅读它。

String text = "";
List<Learning> learning = value.getLearning();
for(Learning m : learning) {
     // I guess, here I am missing something, which is really useful
     String code = m.getCode();
     String os = m.getOs();
     text = text + "Code: " + code + " OS: " + os + ", ";
}
viewHolder.learning.setText(text);

答案 2 :(得分:0)

JSONArray jsonArray = jsonObj.getJSONArray("learning");

for(int i = 0; i < jsonArray.length(); i++)
{
    JSONObject obj  = jsonArray.getJSONObject(i);
    String code = obj.getString("code");
    String os = obj.getString("os");

    Log.i("MyClass", "Code -> " + code);
    Log.i("MyClass", OS -> " + os);

}