java如何跳过JSON中的第一个元素
这是我从JSON解析数据的方式:
private void getData() {
// creating a variable for storing our string.
String url = "https://api.alternative.me/fng/?limit=10&date_format=us";
// creating a variable for request queue.
RequestQueue queue = Volley.newRequestQueue(this.getApplicationContext());
// making a json object request to fetch data from API.
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@SuppressLint("NotifyDataSetChanged")
@Override
public void onResponse(JSONObject response) {
// inside on response method extracting data
// from response and passing it to array list
// on below line we are making our progress
// bar visibility to gone.
loadingPB.setVisibility(View.GONE);
try {
// extracting data from json.
JSONArray dataArray = response.getJSONArray("data");
for (int i = 0; i < 10; i++) {
JSONObject dataObj = dataArray.getJSONObject(i);
String valueClass = dataObj.getString("value_classification");
String value = dataObj.getString("value");
String date = dataObj.getString("timestamp");
// adding all data to our array list.
FnGModalArrayList.add(new FnGModal(valueClass, value, date));
}
// notifying adapter on data change.
FnGRVAdapter.notifyDataSetChanged();
} catch (JSONException e) {
// handling json exception.
e.printStackTrace();
Toast.makeText(FnG.this, "Something went amiss. Please try again later", Toast.LENGTH_SHORT).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// displaying error response when received any error.
NetworkResponse networkResponse = error.networkResponse;
if (networkResponse != null && networkResponse.data != null) {
String jsonError = new String(networkResponse.data);
// Print Error!
}
Toast.makeText(FnG.this, "Something wentaaaamiss. Please try again later", Toast.LENGTH_SHORT).show();
}
}) {
};
// calling a method to add our
// json object request to our queue.
queue.add(jsonObjectRequest);
}
这是我的JSON文件:
{
"name": "Fear and Greed Index",
"data": [
{
"value": "21",
"value_classification": "Extreme Fear",
"timestamp": "11-27-2021",
"time_until_update": "-1637957496"
},
{
"value": "47",
"value_classification": "Neutral",
"timestamp": "11-26-2021"
},
{
"value": "32",
"value_classification": "Fear",
"timestamp": "11-25-2021"
},
{
"value": "42",
"value_classification": "Fear",
"timestamp": "11-24-2021"
},
{
"value": "33",
"value_classification": "Fear",
"timestamp": "11-23-2021"
},
{
"value": "50",
"value_classification": "Neutral",
"timestamp": "11-22-2021"
},
{
"value": "49",
"value_classification": "Neutral",
"timestamp": "11-21-2021"
},
{
"value": "43",
"value_classification": "Fear",
"timestamp": "11-20-2021"
},
{
"value": "34",
"value_classification": "Fear",
"timestamp": "11-19-2021"
},
{
"value": "54",
"value_classification": "Neutral",
"timestamp": "11-18-2021"
}
],
"metadata": {
"error": null
}
}
我想跳过这个,解析数据时的第一个元素。有什么办法吗
{
"value": "21",
"value_classification": "Extreme Fear",
"timestamp": "11-27-2021",
"time_until_update": "-1637957496"
},
我已经尝试了很多方法来跳过第一个元素,但是没有帮助,跳过第一个元素的原因我不希望今天的元素在那里,但是所有之前的元素都在那里。对不起,英语不好
共 (0) 个答案