如题:配置文件有一个这样的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;
}
}
请教大神...我哪操作错了