我正在尝试将结果存储在变量中,以便可以在循环外引用它,并且无法在我的一生中使它正常工作,我们将不胜感激
在下面查看我的代码
public class MainActivity extends AppCompatActivity {
private TextView mTextViewResult;
private RequestQueue mQueue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextViewResult = findViewById(R.id.text_view_result);
Button buttonParse = findViewById(R.id.button_parse);
mQueue = Volley.newRequestQueue(this);
buttonParse.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
jsonParse();
}
});
}
private void jsonParse() {
String url = "https://cdn.sportmonks.com/soccer/json/champions-league-20172018-standings.json";
JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("data");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject data = jsonArray.getJSONObject(i);
String GroupName = data.getString("name");
int position = data.getInt("position");
String TeamName = data.getString("team_name");
mTextViewResult.append(GroupName + ", " + String.valueOf(position) + ", " + TeamName + "\n\n");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
mQueue.add(request);
}
}
答案 0 :(得分:2)
使用#map代替#each:
movie_list = str.map do |movie_list|
File.basename(movie_list)
end