gpt4 book ai didi

android - 在 Android 中使用 JSON 从网站解析数组

转载 作者:行者123 更新时间:2023-11-29 17:56:43 24 4
gpt4 key购买 nike

我想从下面给出的数据中解析一个特定的数组,特别是太阳能:

{
"Month":
{"1":"January",
"2":"February",
"3":"March",
"4":"April",
"5":"May",
"6":"June",
"7":"July",
"8":"August",
"9":"September",
"10":"October",
"11":"November",
"12":"December"},
"Air":
{"1":"26.6",
"2":"26.9",
"3":"27.2",
"4":"27.6",
"5":"27.6",
"6":"27.1",
"7":"26.7",
"8":"26.5",
"9":"26.5",
"10":"26.8",
"11":"26.7",
"12":"26.4"},
"Humid":
{"1":"79.5%",
"2":"75.6%",
"3":"75.8%",
"4":"75.9%",
"5":"77.5%",
"6":"78.2%",
"7":"79.0%",
"8":"81.5%",
"9":"80.5%",
"10":"77.2%",
"11":"76.7%",
"12":"79.7%"},
"Solar":
{"1":"5.87",
"2":"6.51",
"3":"6.77",
"4":"6.42",
"5":"5.51",
"6":"4.86",
"7":"4.95",
"8":"5.09",
"9":"5.92",
"10":"6.22",
"11":"6.12",
"12":"5.82"},
"Atm":
{"1":"101.1",
"2":"101.1",
"3":"101.1",
"4":"101.0",
"5":"101.0",
"6":"101.0",
"7":"101.1",
"8":"101.1",
"9":"101.2",
"10":"101.2",
"11":"101.2",
"12":"101.2"},
"Wind":
{"1":"3.7",
"2":"3.9",
"3":"3.0",
"4":"2.9",
"5":"3.7",
"6":"4.0",
"7":"3.5",
"8":"3.7",
"9":"3.0",
"10":"3.7",
"11":"3.9",
"12":"3.4"},
"Earth":
{"1":"28.5",
"2":"28.6",
"3":"29.3",
"4":"30.0",
"5":"29.9",
"6":"29.5",
"7":"29.3",
"8":"29.0",
"9":"29.1",
"10":"28.9",
"11":"28.5",
"12":"28.4"},
"HDD":
{"1":"0",
"2":"0",
"3":"0",
"4":"0",
"5":"0",
"6":"0",
"7":"0",
"8":"0",
"9":"0",
"10":"0",
"11":"0",
"12":"0"},
"CDD":
{"1":"514",
"2":"477",
"3":"532",
"4":"529",
"5":"545",
"6":"511",
"7":"516",
"8":"509",
"9":"495",
"10":"519",
"11":"502",
"12":"509"}
}

我试图了解如何使用不同的教程来做到这一点,但我似乎无法继续前进。我只需要提取 JSONArray 并将其转换为 String 数组并将这些值存储到变量中。现在,我可以做到这一点:

public JSONObject solardata() throws ClientProtocolException, IOException, JSONException {
StringBuilder sb = new StringBuilder(URL);
HttpGet get = new HttpGet(sb.toString());
HttpResponse r = client.execute(get);
int status = r.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity e = r.getEntity();

这之后我应该做什么?如何获取 JSONArray

最佳答案

  1. Google 是您的 friend 。提问前请先搜索。简单搜索“android httpget json”即可获得大量示例。 Here's第一击完全符合您的要求。
  2. 您的 JSON 中没有数组。它只是一个带有键和值的普通 JSON 对象。

关于android - 在 Android 中使用 JSON 从网站解析数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18791705/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com