gpt4 book ai didi

java - Android 天气应用程序将字符串数组转换为 double 组有困难

转载 作者:行者123 更新时间:2023-12-02 10:51:55 26 4
gpt4 key购买 nike

任何人都可以帮助我吗?我尝试使用双重解析进行转换,但对我不起作用。这是我想循环获取温度的数组

{"temp":17.49,"pressure":1022,"humidity":59,"temp_min":16,"temp_max":19}

我尝试以这种方式输入,但它显示一些错误

 String  degree =jsonObject.getString("main");
Log.i("systemmmm",degree);
JSONArray arrr=new JSONArray(degree);

for(int i=0;i<arrr.length();i++){
JSONObject parts=arrr.getJSONObject(i);

String temp;
temp= parts.getString("temp");
Log.i("heeeey",temp);

//Log.i("gaaab", String.valueOf(qaybs.getDouble("temp")));
}

错误

**W/System.err: org.json.JSONException: Value {"temp":17.49,"pressure":1022,"humidity":59,"temp_min":16,"temp_max":19} of type org.json.JSONObject cannot be converted to JSONArray

W/System.err:位于 org.json.JSON.typeMismatch(JSON.java:111)**

最佳答案

这不是一个数组,而是一个 JSON 对象。数组周围有方括号 [ ]

尝试

JSONObject obj = new JSONObject(degree);
double temp = obj.getDouble("temp");

关于java - Android 天气应用程序将字符串数组转换为 double 组有困难,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52104470/

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