花括号,里面key:value
1、pom.xml中需要配置fastjson
JSON是抽象类
JSONObject继承JSON,实现了Map<String,Object>
JSONObject类
public class JSONObject
extends JSON implements Map<String, Object>, Cloneable, Serializable, InvocationHandler
构造方法:
public JSONObject()
public JSONObject(Map<String, Object> map)
public JSONObject(boolean ordered)
....
普通方法:
1、Map接口中常用方法:
public int size()
public boolean isEmpty()
public boolean containsKey(Object key)
public Object get(Object key)
public Object put(String key, Object value)
public void putAll(Map<? extends String, ? extends Object> m)
public void clear()
public Object remove(Object key)
public Set<String> keySet()
public Collection<Object> values()
public Set<Map.Entry<String, Object>> entrySet()
public Object clone()
public boolean equals(Object obj)
public int hashCode()
2、自己的:
public JSONObject getJSONObject(String key)
public JSONArray getJSONArray(String key)
public <T> T getObject(String key, Class<T> clazz)
public Boolean getBoolean(String key)
public byte[] getBytes(String key)
public boolean getBooleanValue(String key)
public Byte getByte(String key)
public Integer getInteger(String key)
public int getIntValue(String key)
public Date getDate(String key)
public java.sql.Date getSqlDate(String key)
public Map<String, Object> getInnerMap()
........
JSONArray类
public class JSONArray
extends JSON implements List<Object>, Cloneable, RandomAccess, Serializable
构造方法:
public JSONArray()
public JSONArray(List<Object> list)
public JSONArray(int initialCapacity)
普通方法:
1、List接口中方法:
public int size()
public boolean isEmpty()
public boolean contains(Object o)
public Iterator<Object> iterator()
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(Object e)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
public boolean addAll(Collection<? extends Object> c)
public boolean addAll(int index, Collection<? extends Object> c)
public void clear()
public Object set(int index, Object element)
public void add(int index, Object element)
public Object remove(int index)
public int indexOf(Object o)
public int lastIndexOf(Object o)
public List<Object> subList(int fromIndex, int toIndex)
public Object get(int index)
public Object clone()
public boolean equals(Object obj)
public int hashCode()
2、自己的:
public JSONObject getJSONObject(int index)
public JSONArray getJSONArray(int index)
public <T> T getObject(int index, Class<T> clazz)
public <T> T getObject(int index, Type type)
public Boolean getBoolean(int index)
public boolean getBooleanValue(int index)
public Byte getByte(int index)
public byte getByteValue(int index)
public Short getShort(int index)
public short getShortValue(int index)
public Integer getInteger(int index)
public int getIntValue(int index)
public Long getLong(int index)
public long getLongValue(int index)
public String getString(int index)
public java.util.Date getDate(int index)
public java.sql.Date getSqlDate(int index)
public java.sql.Timestamp getTimestamp(int index)
public <T> List<T> toJavaList(Class<T> clazz)
JSON类(抽象类)
public abstract class JSON implements JSONStreamAware, JSONAware
常用方法:
public static Object parse(String text)
public static JSONObject parseObject(String text)
public static JSONArray parseArray(String text)
public static <T> List<T> parseArray(String text, Class<T> clazz)