gpt4 book ai didi

java - Android 时间和字符串

转载 作者:行者123 更新时间:2023-12-01 11:15:16 26 4
gpt4 key购买 nike

在我的应用程序中,我从 sql 接收字符序列,如下所示:

"{"1":{"from":"540","to":"1020"},"2":{"from":"540","to":"1020"},"3":{"from":"540","to":"1020"},"4":{"from":"540","to":"1020"},"5":{"from":"540","to":"1020"},"6":{"from":"540","to":"1020"},"7":{"from":"540","to":"1020"}}"

这是完整的一周,日复一日,自午夜以来的分钟。我知道如何使用它,但我现在不知道如何在感知字符串上裁剪它,它应该看起来像:

String monday_open = 540;
String monday_close = 1020;

到周末也是如此也许有人知道裁剪这个序列的简单方法?

最佳答案

这个

"{"1":{"from":"540","to":"1020"},"2":{"from":"540","to":"1020"},"3":{"from":"540","to":"1020"},"4":{"from":"540","to":"1020"},"5":{"from":"540","to":"1020"},"6":{"from":"540","to":"1020"},"7":{"from":"540","to":"1020"}}"

是一个json文本

我的 json 字符串

{
"coord": {
"lon": 51.42,
"lat": 35.69
},
"weather": [
{
"id": 721,
"main": "Haze",
"description": "haze",
"icon": "50n"
}
],
"base": "cmc stations",
"main": {
"temp": 298.45,
"pressure": 1016,
"humidity": 39,
"temp_min": 298.15,
"temp_max": 299.15
},
"wind": {
"speed": 2.1,
"deg": 240
},
"clouds": {
"all": 40
},
"dt": 1439151053,
"sys": {
"type": 1,
"id": 7032,
"message": 0.0034,
"country": "IR",
"sunrise": 1439084924,
"sunset": 1439134215
},
"id": 112931,
"name": "Tehran",
"cod": 200
}

我用方法解析它:

private void jsonRead(String file) throws JSONException {
JSONObject root=new JSONObject(file);
JSONArray jsonArray = root.optJSONArray("weather");
JSONObject jo2=root.optJSONObject("main");
for(int i=0; i < jsonArray.length(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
dama.setText(jsonObject.getString("description"));
}
rotobat.setText(jo2.getString("humidity"));
}

关于java - Android 时间和字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31908443/

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