JSONtokener的源代码,了解JSONtokener.

本文主要探讨了在服务器处理Android客户端发送的数据时,如何使用JSONTokener对象。提供了JSONTokener的完整源码链接,帮助开发者深入了解其工作原理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

当我们一个服务器从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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值