解决方案 »

  1.   

    我写过一个这样的互转, 你去看看吧http://blog.csdn.net/moneyshi/article/details/24986125
      

  2.   


    看了下,确实挺不错的,但是那个JsonValue是什么啊 能告知一下么
      

  3.   

    看你要用什么了,Gson,Jackson,fastjson
    推荐你用fastjsonhttp://wenku.baidu.com/link?url=c3yYO-tQJBI1hjEvxKEd6dUnOniRTxBUmbk6cfZCBts7wmijvtRU5EZMceSBaM7go4q-c2SN5lmk4CNspQWkGfBPblDFQUJNxE6x7OicSuy
      

  4.   


    看了下,确实挺不错的,但是那个JsonValue是什么啊 能告知一下么额....硬要贴代码么?
    好吧,全给你。import java.util.HashMap;
    import java.util.List;
    public class JsonValue {
    private String value;
    private HashMap<String,JsonValue> map;
    private List<HashMap<String,JsonValue>> list;
    private Boolean bool; public JsonValue(){
    } public JsonValue(String value){
    setValue(value);
    }

    public JsonValue(Integer value){
    setValue(StringUtil.valueOf(value));
    }

    public JsonValue(Long value){
    setValue(String.valueOf(value));
    }

    public JsonValue(Boolean bool){
    setBool(bool);
    } public JsonValue(HashMap<String, JsonValue>  map){
    setMap(map);
    } public JsonValue(List<HashMap<String, JsonValue>> list){
    setList(list);
    } public String getValue() {
    return value;
    }

    public void setValue(String value) {
    this.value = value;
    } public HashMap<String, JsonValue> getMap() {
    return map;
    }

    public void setMap(HashMap<String, JsonValue> map) {
    this.map = map;
    } public List<HashMap<String, JsonValue>> getList() {
    return list;
    }

    public void setList(List<HashMap<String, JsonValue>> list) {
    this.list = list;
    }

    public Boolean getBool() {
    return bool;
    } public void setBool(Boolean bool) {
    this.bool = bool;
    } public Class getValueType(){
    if(getValue() != null){
    return getValue().getClass();
    }
    if(getMap() != null){
    return getMap().getClass();
    }
    if(getList() != null){
    return getList().getClass();
    }
    if(getBool() != null){
    return getBool().getClass();
    }
    return null;
    } public Object getJsonValue(){
    if(getValue() != null){
    return getValue();
    }
    if(getMap() != null){
    return getMap();
    }
    if(getList() != null){
    return getList();
    }
    if(getBool() != null){
    return getBool();
    }
    return null;
    }}