List<Map<String,Object>>打印输出效果[{3=dong,2=xiao,1=wang,4=haha},{3=dong,2=xiao,1=wang,4=haha}]
list集合里的有两条map集合,每条map集合中有4个<key,value>对
List打印是:[str1, str2...]
Map打印是:{key1=value1, key2=value2}
List<Map<>>打印是:[{key1=value1, key2=value2}, {key1=value1, key2=value2}]
JSON打印是:
{"itemKey":[
{"key1":1 , "key2":"07-18"},
{"key1":2 , "key2":"07-19"}
]}
测试代码:
package com.aoyang.wxapp.controller.cms.vehicleweixin;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
public class Test {
public static void main(String[] args) {
List<String> listStr = new ArrayList<String>();
listStr.add("str1");
listStr.add("str2");
System.out.println(listStr.toString()); //[str1, str2]
Map<String, String> map = new HashMap<String, String>();
map.put("key1", "value1");
map.put("key2", "value2");
System.out.println(map.toString()); //{key1=value1, key2=value2}
List<Map<String, String>> listMap = new ArrayList<Map<String, String>>();
listMap.add(map);
listMap.add(map);
//[{key1=value1, key2=value2}, {key1=value1, key2=value2}]
System.out.println(listMap.toString());
//JSONObject是继承Map<String, Object>,并且都是使用的Map中的方法
JSONObject jsonObj = new JSONObject();
jsonObj.put("key1", "value1");
jsonObj.put("key2", "value2");
System.out.println(jsonObj.toString()); //{"key1":"value1","key2":"value2"}
//JSONArray是继承List<Object>,并且都是使用的List中的方法
JSONArray jsonArr = new JSONArray();
jsonArr.add(jsonObj);
jsonArr.add(jsonObj);
//[{"key1":"value1","key2":"value2"},{"key1":"value1","key2":"value2"}]
System.out.println(jsonArr.toString());
JSONObject jsonObjA = new JSONObject();
jsonObjA.put("itemKey", jsonArr);
//{"itemKey":[{"key1":"value1","key2":"value2"},{"key1":"value1","key2":"value2"}]}
System.out.println(jsonObjA.toString());
}
}
打印输出为:
[str1, str2]
{key1=value1, key2=value2}
[{key1=value1, key2=value2}, {key1=value1, key2=value2}]
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/D:/DEVELOPE/.m2/repository/org/slf4j/slf4j-log4j12/1.7.21/slf4j-log4j12-1.7.21.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/DEVELOPE/.m2/repository/ch/qos/logback/logback-classic/1.1.2/logback-classic-1.1.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/D:/DEVELOPE/.m2/repository/org/apache/activemq/activemq-all/5.9.0/activemq-all-5.9.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
{"key1":"value1","key2":"value2"}
[{"key1":"value1","key2":"value2"},{"key1":"value1","key2":"value2"}]
{"itemKey":[{"key1":"value1","key2":"value2"},{"key1":"value1","key2":"value2"}]}