mobile/android/thirdparty/org/json/simple/JSONArray.java

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mobile/android/thirdparty/org/json/simple/JSONArray.java	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     1.4 +/*
     1.5 + * $Id: JSONArray.java,v 1.1 2006/04/15 14:10:48 platform Exp $
     1.6 + * Created on 2006-4-10
     1.7 + */
     1.8 +package org.json.simple;
     1.9 +
    1.10 +import java.io.IOException;
    1.11 +import java.io.Writer;
    1.12 +import java.util.ArrayList;
    1.13 +import java.util.Iterator;
    1.14 +import java.util.List;
    1.15 +
    1.16 +
    1.17 +/**
    1.18 + * A JSON array. JSONObject supports java.util.List interface.
    1.19 + * 
    1.20 + * @author FangYidong<fangyidong@yahoo.com.cn>
    1.21 + */
    1.22 +public class JSONArray extends ArrayList implements List, JSONAware, JSONStreamAware {
    1.23 +	private static final long serialVersionUID = 3957988303675231981L;
    1.24 +
    1.25 +    /**
    1.26 +     * Encode a list into JSON text and write it to out. 
    1.27 +     * If this list is also a JSONStreamAware or a JSONAware, JSONStreamAware and JSONAware specific behaviours will be ignored at this top level.
    1.28 +     * 
    1.29 +     * @see org.json.simple.JSONValue#writeJSONString(Object, Writer)
    1.30 +     * 
    1.31 +     * @param list
    1.32 +     * @param out
    1.33 +     */
    1.34 +	public static void writeJSONString(List list, Writer out) throws IOException{
    1.35 +		if(list == null){
    1.36 +			out.write("null");
    1.37 +			return;
    1.38 +		}
    1.39 +		
    1.40 +		boolean first = true;
    1.41 +		Iterator iter=list.iterator();
    1.42 +		
    1.43 +        out.write('[');
    1.44 +		while(iter.hasNext()){
    1.45 +            if(first)
    1.46 +                first = false;
    1.47 +            else
    1.48 +                out.write(',');
    1.49 +            
    1.50 +			Object value=iter.next();
    1.51 +			if(value == null){
    1.52 +				out.write("null");
    1.53 +				continue;
    1.54 +			}
    1.55 +			
    1.56 +			JSONValue.writeJSONString(value, out);
    1.57 +		}
    1.58 +		out.write(']');
    1.59 +	}
    1.60 +	
    1.61 +	public void writeJSONString(Writer out) throws IOException{
    1.62 +		writeJSONString(this, out);
    1.63 +	}
    1.64 +	
    1.65 +	/**
    1.66 +	 * Convert a list to JSON text. The result is a JSON array. 
    1.67 +	 * If this list is also a JSONAware, JSONAware specific behaviours will be omitted at this top level.
    1.68 +	 * 
    1.69 +	 * @see org.json.simple.JSONValue#toJSONString(Object)
    1.70 +	 * 
    1.71 +	 * @param list
    1.72 +	 * @return JSON text, or "null" if list is null.
    1.73 +	 */
    1.74 +	public static String toJSONString(List list){
    1.75 +		if(list == null)
    1.76 +			return "null";
    1.77 +		
    1.78 +        boolean first = true;
    1.79 +        StringBuffer sb = new StringBuffer();
    1.80 +		Iterator iter=list.iterator();
    1.81 +        
    1.82 +        sb.append('[');
    1.83 +		while(iter.hasNext()){
    1.84 +            if(first)
    1.85 +                first = false;
    1.86 +            else
    1.87 +                sb.append(',');
    1.88 +            
    1.89 +			Object value=iter.next();
    1.90 +			if(value == null){
    1.91 +				sb.append("null");
    1.92 +				continue;
    1.93 +			}
    1.94 +			sb.append(JSONValue.toJSONString(value));
    1.95 +		}
    1.96 +        sb.append(']');
    1.97 +		return sb.toString();
    1.98 +	}
    1.99 +
   1.100 +	public String toJSONString(){
   1.101 +		return toJSONString(this);
   1.102 +	}
   1.103 +	
   1.104 +	public String toString() {
   1.105 +		return toJSONString();
   1.106 +	}
   1.107 +
   1.108 +	
   1.109 +		
   1.110 +}

mercurial