请教后端大神,这个怎么获取不到转化后配置的list

请教后端大神,这个怎么获取不到转化后配置的list

问题描述:

如题:配置文件有一个这样的json

pushConfig=[{"channel":"rjs",\
"configMJB":{"appID":"DHcGDs8bDd8rgl5tFSJSV7",\
"appKey":"1LxEoJPhMZ65chrVrhirC3",\
"masterKey":"hn5Cy0AMfy8oLu9CLGNrJA"}}]

注入配置文件里面内容

  <bean id="configFactory"  class="com.rjs.marketing.app.config.ConfigFactory" init-method="init">
        <property name="pushConfig" value="${pushConfig}"/>
    </bean>

有这么个类接收

public class ConfigFactory {

//这里需要把json字符串转换成list
  private String pushConfig;
    private List<Map<String, Map<String, String>>> pushConfigList;

这是操作;
  private List<Map<String, Map<String, String>>> initPushConfigList() throws Exception {
        List<Map<String, Map<String, String>>> configList = JsonUtil.jsonStrToList(this.pushConfig, PushConfig.class);
        this.pushConfigList = configList;
        return this.pushConfigList;
    }

}

这是jsonStrToList操作

 public static <T> List<T> jsonStrToList(String jsonStr, Class<?> clazz) throws JsonParseException, JsonMappingException, IOException {
        List<T> list = Lists.newArrayList();
        if (StringUtils.isEmpty(jsonStr)) {
            return list;
        }
        // 指定容器结构和类型(这里是ArrayList和clazz)
        TypeFactory t = TypeFactory.defaultInstance();
        list = objectMapper.readValue(jsonStr,
                t.constructCollectionType(ArrayList.class, clazz));
        return list;
    }

这是获取,问题是获取的list是个[], 是空啊啊啊啊啊

List<Map<String, Map<String, String>>> list = configFactory.getPushConfigList();
        for (Map<String, Map<String, String>> map : list) {
            Map<String, String> map2 = map.get("configMJB");
            String appID = map2.get("appID");
            String appKey = map2.get("appKey");
            String masterKey = map2.get("masterKey");
            if(pushMsg.getPlatform() != null && !pushMsg.getPlatform().getPlatform().contains("MAJIABAO")){
                if(!"rjs".equals(map.get("channel"))){
                    continue;
                }
            } 

请教大神...我哪操作错了

pushConfig=[{"channel":"rjs",\
"configMJB":{"appID":"DHcGDs8bDd8rgl5tFSJSV7",\
"appKey":"1LxEoJPhMZ65chrVrhirC3",\
"masterKey":"hn5Cy0AMfy8oLu9CLGNrJA"}}]

pushConfig 整体是个List> 不是List>>
configMJB 这个字段你取出来可以再转换成 Map 解析

调试看看那个list 赋值的时候为什么是空的。应该是你把JSON字符串转换成list的时候出错了,没转换完成,所以list接收不到数据,调试看看就知道哪一步出了问题

,不可以,谢谢,建议你百度一下