为了账号安全,请及时绑定邮箱和手机立即绑定

使用 Json 对象文件创建数组列表

使用 Json 对象文件创建数组列表

Smart猫小萌 2019-03-28 15:11:41
检查下面的代码:String jsonString = writer.toString();         JSONObject jsonObj = new JSONObject(jsonString);          defaultCurrencyValue = jsonObj.getString(DefaultCurrencyKey);         currenciesTypes = jsonObj.get(CurrenciesKey);当我使用 Debugger 时获得 curenciesType 对象类变量的值。currenciesTypes JSONObject  (id=830084916104)        myHashMap   HashMap  (id=830084916120)           [0] HashMap$HashMapEntry  (id=830084916440)              key "PKR" (id=830084916256)              value   "Rs" (id=830084916368)           [1] HashMap$HashMapEntry  (id=830084917208)              key "EUR" (id=830084917064)              value   "€" (id=830084917176)            [2] HashMap$HashMapEntry  (id=830084916696)          [3] HashMap$HashMapEntry  (id=830084916952)如何在数组列表中保存 key和 它的 values?
查看完整描述

2 回答

?
隔江千里

TA贡献1906条经验 获得超10个赞

在两个 arraylists 保存 key 和 values:

String jsonString = writer.toString();
        JSONObject jsonObj = new JSONObject(jsonString); 
         currenciesTypes = jsonObj.get(CurrenciesKey);
        ArrayList<String> keys=new ArrayList<String>();
        ArrayList<String> values=new ArrayList<String>();
        Iterator<String> iterator=currencyType.keys();
        while(iterator.hasNext())
        {
              String key=iterator.next();
              keys.add(key);
              values.add(currencyType.get(key));
        }


查看完整回答
反对 回复 2019-04-27
?
Helenr

TA贡献1780条经验 获得超4个赞

String jsonString = writer.toString();
    JSONObject jsonObj = new JSONObject(jsonString); 
    JSONObject currenciesTypes = jsonObj.get(CurrenciesKey);
    List<Pair<String,String>> keyValuePairList=new ArrayList<Pair<String,String>>();
    Iterator<String> iterator=currenciesTypes.keys();
    while(iterator.hasNext())
    {
       String key=iterator.next();
       Pair<String,String> keyValue=new Pair<String,String>(key, (String) currenciesTypes.get(key));
       keyValuePairList.add(keyValue);
    }


查看完整回答
反对 回复 2019-04-27
  • 2 回答
  • 0 关注
  • 596 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号