buyax 2017-08-21 07:40 采纳率: 53.3%
浏览 974
已采纳

请教后端大神,这个怎么获取不到转化后配置的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;
                }
            } 

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

  • 写回答

4条回答 默认 最新

  • FEN_TA 2017-08-21 08:03
    关注

    图片说明

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码
  • ¥15 如何在Linux系统中,但是在window系统上idea里面可以正常运行?(相关搜索:jar包)
  • ¥50 400g qsfp 光模块iphy方案
  • ¥15 两块ADC0804用proteus仿真时,出现异常