我正在使用CryptoCompare提供的API。我需要从此 JSON 对象获取 Symbol 和 Price。
{
"Response": "Success",
"Message": "Do not take life too seriously. You will never get out of it alive.",
"Data": [
{
"Symbol": "USD",
"Price": 5660.94,
"Open24Hour": 5155.13,
"LastUpdateTS": 1507885905,
"Volume24Hours": 222438.875,
"Volume24HoursTo": 1214073220
},
{
"Symbol": "EUR",
"Price": 4757.16,
"Open24Hour": 4318.19,
"LastUpdateTS": 1507885905,
"Volume24Hours": 26488.4023,
"Volume24HoursTo": 120264888
}
],
"Type": 100
}
最佳答案
我建议您将数据存储到List
因此,初始化两个List
List<String> symbol = new ArrayList<String>();
List<String> price = new ArrayList<String>();
然后你可以在这里存储数据
try {
JSONObject json = new JSONObject(response);
JSONArray jArray = json.getJSONArray("Data");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject object = jsonArray.getJSONObject(i);
symbol.add(object.getString("Symbol"));
price.add(object.getString("Price"));
}
} catch (JSONException e) {
e.printStackTrace();
}
这可能对你有帮助
关于java - 如何获取此 JSON 对象并将其解析为 Android textview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46726587/