0

だから、これは私が持っているjson文字列です。

String json ="{\"BPDataList\":[{\"BPL\":5,\"DataID\":\"6deacbc373e74e1794a7*****\",\"HP\":124,\"HR\":82,\"IsArr\":-1,\"LP\":82,\"Lat\":-1,\"Lon\":-1,\"MDate\":1373392309,\"Note\":\"\",\"LastChangeTime\":1373362486,\"DataSource\":\"FromDevice\",\"TimeZone\":\"+0800\"}],\"BPUnit\":0,\"CurrentRecordCount\":50,\"NextPageUrl\":\"https%3a%2f%2fapi.ihealthlabs.com%3a8443%2fopenapiv2%2fuser%2f05dffbe0dd*****%2fbp.json%2f%3fclient_id%3dddb9cbc759*****%26client_secret%3d4738f9d00e*****%26redirect_uri%3dhttp%253a%252f%252fapi.testweb2.com%252foauthtest.aspx%26access_token%3dxpoBt0ThQQ*****%26start_time%3d1342007016%26end_time%3d1405079016%26page_index%3d2%26sc%3dd63493704c*****%26sv%3d113cb40956*****\",\"PageLength\":50,\"PageNumber\":1,\"PrevPageUrl\":\"\",\"RecordCount\":335}";

このコードを使用してマップに保存しています。

Map<String, Object> map = new HashMap<String, Object>();
JSONObject jObject = new JSONObject(json);

Iterator<?> keys = jObject.keys();
while (keys.hasNext()) {
    try {
        String key = (String) keys.next();
        Object value = jObject.getJSONArray(key);
        log.debug("value--" + map);
        map.put(key, value);
    } catch (Exception e) {
        log.trace("getUserBG--", e);
    }
}

ただし、最初の要素、つまり BPDataList のみをマップに格納しています。ここで何が間違っていますか?

これは、印刷したときのマップの内容です。

map:{BPDataList=[{"DataSource":"FromDevice","IsArr":-1,"DataID":"6deacbc373e74e1794a7*****","BPL":5,"HR":82,"MDate":1373392309,"Lat":-1,"Note":"","HP":124,"TimeZone":"+0800","Lon":-1,"LastChangeTime":1373362486,"LP":82}]}

json

{
  "BPDataList": [
    {
      "BPL": 5,
      "DataID": "6deacbc373e74e1794a7*****",
      "HP": 124,
      "HR": 82,
      "IsArr": -1,
      "LP": 82,
      "Lat": -1,
      "Lon": -1,
      "MDate": 1373392309,
      "Note": "",
      "LastChangeTime": 1373362486,
      "DataSource": "FromDevice",
      "TimeZone": "+0800"
    }
  ],
  "BPUnit": 0,
  "CurrentRecordCount": 50,
  "NextPageUrl": "abc",
  "PageLength": 50,
  "PageNumber": 1,
  "PrevPageUrl": "",
  "RecordCount": 335
}
4

1 に答える 1