【发布时间】:2022-01-02 01:29:39
【问题描述】:
我在从 API 获取数据时遇到问题,想知道是否有人可以提供帮助。我基本上“low_14h”的值有许多不同货币的响应。我只想能够提取“usd”中的值并将其放入我的文本框“dailylowtext”中。我可以摆弄并从'low_24h'中获取一些值,但我正在努力从'usd'中获取值。希望这对我想要实现的目标有意义。
我当前的代码是:
RequestQueue 队列 = Volley.newRequestQueue(this); 字符串 url = "https://api.coingecko.com/api/v3/coins/mina-protocol";
JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject jObj=new JSONObject(response.toString());
String usd = jObj.getJSONObject("response").getJSONObject("low_24h").getString("usd").toString();
} catch (JSONException e) {
e.printStackTrace();
}
// TODO Auto-generated method stub
dailylowtext.setText(response.toString());
System.out.println("Response => "+response.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// TODO Auto-generated method stub
}
});
queue.add(jsObjRequest);
【问题讨论】:
-
JSON 实际上是什么样子的?举个例子
-
嗨。谢谢你的文章。问题已得到解决。保重。
标签: java android json android-studio