android - Json Array in Volley Android
问题描述
i had a Uniform Resource Locator (URL) that contain JSON
Array of [1579.39734, 2523,679.59824966966,4327116]
with key name. How can i get the data element of the JSON Array using volley? Can anyone help?
Below is my coding but is not working.
private void loadJsonArray() {
JsonArrayRequest jsArrayRequest = new JsonArrayRequest
(Request.Method.POST, new_url, null, new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
double[] value=new double[3];
pDialog.dismiss();
for (int count =0; count < response.length(); count++) {
try {
value[count]=response.getDouble(count);
}
catch (JSONException e) {
e.printStackTrace();
}
}
text1.setText(String.valueOf(value[0]));
text2.setText(String.valueOf(value[1]));
text3.setText(String.valueOf(value[2]));
text4.setText(String.valueOf(value[3]));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Error....", Toast.LENGTH_SHORT).show();
error.printStackTrace();
}
});
Singleton.getistance(this).addToRequestque(jsArrayRequest);
}
解决方案
试试看
for(int i = 0; i< jsonArray.lenght(); i++){
double value = jsonArray.getDouble(i);
}
推荐阅读
- java - 带圆角的卡片视图具有灰色背景
- spring-kafka - Spring-Kafka 生产者吞吐量远低于纯 java 生产者
- python - 熊猫将列更改为字符串
- xamarin - 使用插件媒体捕获照片将屏幕显示为彩色矩形
- node.js - 如何在 NodeJS 12 Lambda 函数中使用 async/await 将 S3 JSON 文件流式读取到 postgreSQL?
- reporting-services - 2020 年下载的 Report builder 3.0 需要针对 ssrs 2014
- javascript - Javascript:从逗号分隔的数字字符串中删除引号
- javascript - 如何从响应 Cookie 中读取值?
- karate - 在空手道的 JS 函数中调用带有参数的功能
- javascript - 在点击事件上使用时模式不起作用