在我的应用程序中,我从sql接收到char序列,例如:

"{"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
}


我用blew方法解析它:

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"));
}

10-07 13:18
查看更多