Map<String,Map<List<Double>,List<String>>>我定义这种类型

{首都职工体质促进中心={[166.58]=[2017]}, 怀柔区={[163.21]=[2017]}, 房山区={[169.45]=[2016]}, 门头沟区={[167.53]=[2017]}, 石景山区={[166.43]=[2017]}, 东城区={[140.5]=[2016]}, 昌平区={[161.91]=[2016]}, 亦庄经济开发区={[166.75]=[2017]}, 延庆={[162.63]=[2017]}, 密云区={[167.94]=[2016]}, 顺义区={[164.37]=[2017]}, 通州区={[164.08]=[2017], [180.0]=[2015], [161.0]=[2011], [166.0]=[2012], [159.5]=[2014]}}

想要得到这种格式。
[{"data":["166.58"],riqi:["2017"],"name":"首都职工体质促进中心"},
{"data":["163.21"],riqi:["2017"],"name":"怀柔区"},
{"data":["169.45"],riqi:["2017"],"name":"房山区"},
{"data":["167.53"],riqi:["2017"],"name":"门头沟区"}]

Map只是一个键值对,你下面写的json是一个list 每个list里面有一个实体

List> lst = 查询出的数据 这样就行了

Map只是一个键值对,你下面写的json是一个list 每个list里面有一个实体

List <实体类> lst = 查询出的数据 这样就行了

试试元祖,map,list>>
最终的json格式自己手动拼接

tuple


Map, List>> map = new HashMap, List>>();
Map, List> map_1 = new HashMap, List>();
List map_1_list_d = new ArrayList();
List map_1_list_s = new ArrayList();

    map_1_list_d.add(new Double("111.111"));
    map_1_list_s.add("111");
    map_1.put(map_1_list_d, map_1_list_s);

    Map<List<Double>, List<String>> map_2 = new HashMap<List<Double>, List<String>>();
    List<Double> map_2_list_d = new ArrayList<Double>();
    List<String> map_2_list_s = new ArrayList<String>();

    map_2_list_d.add(new Double("222.222"));
    map_2_list_s.add("222");
    map_2.put(map_2_list_d, map_2_list_s);

    map.put("A区", map_1);
    map.put("B区", map_2);

    List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
    Map<String, Object> list_map = null;
    for (String str : map.keySet()) {
        list_map = new HashMap<String, Object>();
        list_map.put("name", str);
        Map<List<Double>, List<String>> map1 = map.get(str);
        for (List<Double> db : map1.keySet()) {

// System.out.println(db.get(0));
// System.out.println(map1.get(db).get(0));
list_map.put("data", db.get(0));
list_map.put("riqi", map1.get(db).get(0));
break;
}
list.add(list_map);
// System.out.println(str);
}
System.out.println(list);

            [{riqi=222, name=B区, data=222.222}, {riqi=111, name=A区, data=111.111}]

那个通州区有好几个年代与数据吗,如果有,把上面的代码调整一下就好了

List> l=new ArrayList>();
String oldStr = "{首都职工体质促进中心={[166.58]=[2017]}, 怀柔区={[163.21]=[2017]}, 房山区={[169.45]=[2016]}, "
+ "门头沟区={[167.53]=[2017]}, 石景山区={[166.43]=[2017]}, 东城区={[140.5]=[2016]}, "
+ "昌平区={[161.91]=[2016]}, 亦庄经济开发区={[166.75]=[2017]}, 延庆={[162.63]=[2017]}, "
+ "密云区={[167.94]=[2016]}, 顺义区={[164.37]=[2017]}, 通州区={[164.08]=[2017]}";
List list=new ArrayList();
Pattern pn=Pattern.compile("[\u4e00-\u9fa5]+\=\{[[^\u4e00-\u9fa5]&&[^\}]]+\}{1}");
Matcher mpn=pn.matcher(oldStr);
while(mpn.find()){
String str=mpn.group();
int start=0;
Map m=new HashMap();
Pattern pname=Pattern.compile("[^\w]*(?==)");
Pattern pdata=Pattern.compile("\d+.\d+");
Pattern priqi=Pattern.compile("2\d{3}");
Matcher mpname=pname.matcher(str);
Matcher mpdata=pdata.matcher(str);
Matcher mpriqi=priqi.matcher(str);
if(mpname.find()){
m.put("name",mpname.group());
start=mpname.end();
}
if(mpdata.find(start)){
m.put("data", mpdata.group());
start=mpname.end();
}
if(mpriqi.find(start))
m.put("riqi", mpriqi.group());
l.add(m);
}
System.out.println(JSON.toJSON(l));


[{"data":"166.58","name":"首都职工体质促进中心","riqi":"2017"},{"data":"163.21","name":"怀柔区","riqi":"2017"},{"data":"169.45","name":"房山区","riqi":"2016"},{"data":"167.53","name":"门头沟区","riqi":"2017"},{"data":"166.43","name":"石景山区","riqi":"2017"},{"data":"140.5","name":"东城区","riqi":"2016"},{"data":"161.91","name":"昌平区","riqi":"2016"},{"data":"166.75","name":"亦庄经济开发区","riqi":"2017"},{"data":"162.63","name":"延庆","riqi":"2017"},{"data":"167.94","name":"密云区","riqi":"2016"},{"data":"164.37","name":"顺义区","riqi":"2017"},{"data":"164.08","name":"通州区","riqi":"2017"}]

我这里用了fastjson转化,也可以用其它方式拼接字符串