当我们一个服务器从android客户端接受数据的时候,我就需要JSONtokener对象,
在此我给大家把源码给找了出来。当然这个是最全的源码网站,包括JSONtokener用到的包。
直接给大家附上http://opensourcejavaphp.net/java/json/net/sf/json/util/JSONTokener.java.html
JSONTokener.java
/*
* Copyright 2002-2009 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.json.util;
import net.sf.json.JSONArray;
import net.sf.json.JSONException;
import net.sf.json.JSONNull;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.regexp.RegexpUtils;
/**
* A JSONTokener takes a source string and extracts characters and tokens from
* it. It is used by the JSONObject and JSONArray constructors to parse JSON
* source strings.
*
* @author JSON.org
* @version 4
*/
public class JSONTokener {
/**
* Get the hex value of a character (base16).
*
* @param c A character between '0' and '9' or between 'A' and 'F' or between
* 'a' and 'f'.
* @return An int between 0 and 15, or -1 if c was not a hex digit.
*/
public static int dehexchar( char c ) {
if( c >= '0' && c <= '9' ){
return c - '0';
}
if( c >= 'A' && c <= 'F' ){
return c - ('A' - 10);
}
if( c >= 'a' && c <= 'f' ){
return c - ('a' - 10);
}
return -1;
}
/**
* The index of the next character.
*/
private int myIndex;
/**
* The source string being tokenized.
*/
private String mySource;
/**
* Construct a JSONTokener from a string.
*
* @param s A source string.
*/
public JSONTokener( String s ) {
this.myIndex = 0;
if( s!= null ) {
s = s.trim();
} else {
s = "";
}
if( s.length() > 0 ){
char first = s.charAt( 0 );
char last = s.charAt( s.length() - 1 );
if( first == '[' && last != ']' ) {
throw syntaxError( "Found starting '[' but missing ']' at the end." );
}
if( first == '{' && last != '}' ) {
throw syntaxError( "Found starting '{' but missing '}' at the end." );
}
}
this.mySource = s;
}
/**
* Back up one character. This provides a sort of lookahead capability, so
* that you can test for a digit or letter before attempting to parse the
* next number or identi