json,jsonObject,jsonArray

这里写目录标题

    • jsonObject源码
    • jsonArray

jsonObject源码

package org.json.simple;

import java.io.IOException;
import java.io.Writer;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class JSONObject extends HashMap implements Map, JSONAware, JSONStreamAware {
    private static final long serialVersionUID = -503443796854799292L;

    public JSONObject() {
    }

    public JSONObject(Map map) {
        super(map);
    }

    public static void writeJSONString(Map map, Writer out) throws IOException {
        if (map == null) {
            out.write("null");
        } else {
            boolean first = true;
            Iterator iter = map.entrySet().iterator();
            out.write(123);

            while(iter.hasNext()) {
                if (first) {
                    first = false;
                } else {
                    out.write(44);
                }

                Entry entry = (Entry)iter.next();
                out.write(34);
                out.write(escape(String.valueOf(entry.getKey())));
                out.write(34);
                out.write(58);
                JSONValue.writeJSONString(entry.getValue(), out);
            }

            out.write(125);
        }
    }

    public void writeJSONString(Writer out) throws IOException {
        writeJSONString(this, out);
    }

    public static String toJSONString(Map map) {
        if (map == null) {
            return "null";
        } else {
            StringBuffer sb = new StringBuffer();
            boolean first = true;
            Iterator iter = map.entrySet().iterator();
            sb.append('{');

            while(iter.hasNext()) {
                if (first) {
                    first = false;
                } else {
                    sb.append(',');
                }

                Entry entry = (Entry)iter.next();
                toJSONString(String.valueOf(entry.getKey()), entry.getValue(), sb);
            }

            sb.append('}');
            return sb.toString();
        }
    }

    public String toJSONString() {
        return toJSONString(this);
    }

    private static String toJSONString(String key, Object value, StringBuffer sb) {
        sb.append('"');
        if (key == null) {
            sb.append("null");
        } else {
            JSONValue.escape(key, sb);
        }

        sb.append('"').append(':');
        sb.append(JSONValue.toJSONString(value));
        return sb.toString();
    }

    public String toString() {
        return this.toJSONString();
    }

    public static String toString(String key, Object value) {
        StringBuffer sb = new StringBuffer();
        toJSONString(key, value, sb);
        return sb.toString();
    }

    public static String escape(String s) {
        return JSONValue.escape(s);
    }
}

jsonArray

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.json.simple;

import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamAware {
    private static final long serialVersionUID = 3957988303675231981L;

    public JSONArray() {
    }

    public static void writeJSONString(List list, Writer out) throws IOException {
        if (list == null) {
            out.write("null");
        } else {
            boolean first = true;
            Iterator iter = list.iterator();
            out.write(91);

            while(iter.hasNext()) {
                if (first) {
                    first = false;
                } else {
                    out.write(44);
                }

                Object value = iter.next();
                if (value == null) {
                    out.write("null");
                } else {
                    JSONValue.writeJSONString(value, out);
                }
            }

            out.write(93);
        }
    }

    public void writeJSONString(Writer out) throws IOException {
        writeJSONString(this, out);
    }

    public static String toJSONString(List list) {
        if (list == null) {
            return "null";
        } else {
            boolean first = true;
            StringBuffer sb = new StringBuffer();
            Iterator iter = list.iterator();
            sb.append('[');

            while(iter.hasNext()) {
                if (first) {
                    first = false;
                } else {
                    sb.append(',');
                }

                Object value = iter.next();
                if (value == null) {
                    sb.append("null");
                } else {
                    sb.append(JSONValue.toJSONString(value));
                }
            }

            sb.append(']');
            return sb.toString();
        }
    }

    public String toJSONString() {
        return toJSONString(this);
    }

    public String toString() {
        return this.toJSONString();
    }
}

你可能感兴趣的:(日常,Java)