简体   繁体   English

从Multimap中的键获取JSONArray值

[英]get JSONArray value from key in Multimap

I have a multimap. 我有一个多图。

Multimap<String,JSONArray> map = ArrayListMultimap.create();

I am trying to get all values based from key. 我试图从键获取所有值。 But when I am trying, I am getting the following error: 但是,当我尝试时,出现以下错误:

 Exception details:  java.lang.ClassCastException: 
 com.google.common.collect.AbstractMultimap$RandomAccessWrappedList cannot be 
 cast to org.json.JSONArray
 java.lang.ClassCastException: 
 com.google.common.collect.AbstractMultimap$RandomAccessWrappedList cannot be 
 cast to org.json.JSONArray

I am trying to do : 我正在尝试:

for (final String str : map.keySet()) {
            final JSONArray jsonArr = (JSONArray) map.get(str);
           //do something
}

Can anyone suggest how to get the jsonArray for each keyset? 谁能建议如何为每个键集获取jsonArray?

You can iterate through values of Multimap like this. 您可以像这样遍历Multimap的值。

  for (Object value1 : map.values()) {
    JSONArray  val  = (JSONArray) value1;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM