标签:ring cti hashmap pdo etc ash logo cep [1]
正常的JSON数据
[
{"key":"UI","value":"UII"},
{"key":"Font","value":"Fontt"}
]
我的JSON数据
[
{"UI":UII"},
{"Font":"Fontt"}
]
AJAX传data给后台,读取properties配置文件,
UIConfigurate.Group.UI.module=Color:Colorr|Logo_text:Logo_textt
切割后变成,放进map里面,用ArrayList封装,最后封装成JSON
@RequestMapping(value="/testGetValueByKey")
@ResponseBody
public String getValueByKey(@RequestBody String key){
System.out.println(key);
Properties pps = new Properties();
try{
FileInputStream is=new FileInputStream("E:\\dingh\\workspace\\pcs\\src\\dropdown.properties");
//InputStream is=this.getClass().getResourceAsStream("/dropdown.properties");
pps.load(is);
is.close();
}catch(IOException e){
e.printStackTrace();
}
String value = (String) pps.get(key);
List<Map<String,Object>> list = new ArrayList<Map<String,Object>>();
String[] splitValue = value.split("\\|");
// Map<String,Object> map =new LinkedHashMap<String,Object>();
Map<String,Object> map;
for (String str : splitValue) {
map = new HashMap<String,Object>();
String[] test = str.split(":");
map.put(test[0], test[1]);
list.add(map);
}
System.out.println(JSON.toJSONString(list));
return JSON.toJSONString(list);
}
}
AJAX循环打印
function getGroup(){
$("#group").empty();
$("#group").append("<option>All</option>");
var category = document.getElementById("category").value;
var first = "UIConfigurate.Group.";
var last = ".module";
var cat = first+category+last;
// alert(pro);
$.ajax({
timeout: 3000,
async: false,
type: "POST",
url: "testGetValueByKey",
dataType: "json",
contentType: "application/json; charset=utf-8",
data:cat,
success: function (data) {
if(cat!="UIConfigurate.Group.All.module"){
for(var i=0;i<data.length;i++){
for(var key in data[i]){
// alert(key);
// alert(data[i][key]);
$("#group").append("<option value=‘"+data[i][key]+"‘>"+key+"</option>");
}
}
}
}
});
}
读取不标准的JSON数据
标签:ring cti hashmap pdo etc ash logo cep [1]
原文地址:http://www.cnblogs.com/huangd/p/7859441.html