/*
* Copyright 1999-2101 Alibaba Group.
*
* 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 com.alibaba.fastjson.parser;
import static com.alibaba.fastjson.parser.JSONToken.COLON;
import static com.alibaba.fastjson.parser.JSONToken.COMMA;
import static com.alibaba.fastjson.parser.JSONToken.EOF;
import static com.alibaba.fastjson.parser.JSONToken.ERROR;
import static com.alibaba.fastjson.parser.JSONToken.LBRACE;
import static com.alibaba.fastjson.parser.JSONToken.LBRACKET;
import static com.alibaba.fastjson.parser.JSONToken.LITERAL_STRING;
import static com.alibaba.fastjson.parser.JSONToken.LPAREN;
import static com.alibaba.fastjson.parser.JSONToken.RBRACE;
import static com.alibaba.fastjson.parser.JSONToken.RBRACKET;
import static com.alibaba.fastjson.parser.JSONToken.RPAREN;
import java.lang.ref.SoftReference;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.HashSet;
import java.util.Locale;
import java.util.TimeZone;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.util.Base64;
//这个类,为了性能优化做了很多特别处理,一切都是为了性能!!!
/**
* @author wenshao<szujobs@hotmail.com>
*/
public final class JSONScanner implements JSONLexer {
public final static byte EOI = 0x1A;
private final char[] buf;
private int bp;
private final int buflen;
private int eofPos;
/**
* The current character.
*/
private char ch;
/**
* The token's position, 0-based offset from beginning of text.
*/
private int pos;
/**
* A character buffer for literals.
*/
private char[] sbuf;
private int sp;
/**
* number start position
*/
private int np;
/**
* The token, set by nextToken().
*/
private int token;
private Keywords keywods = Keywords.DEFAULT_KEYWORDS;
private final static ThreadLocal<SoftReference<char[]>> sbufRefLocal = new ThreadLocal<SoftReference<char[]>>();
private int features = JSON.DEFAULT_PARSER_FEATURE;
private Calendar calendar = null;
private boolean resetFlag = false;
public int resetCount = 0;
public JSONScanner(String input){
this(input, JSON.DEFAULT_PARSER_FEATURE);
}
public JSONScanner(String input, int features){
this(input.toCharArray(), input.length(), features);
}
public JSONScanner(char[] input, int inputLength){
this(input, inputLength, JSON.DEFAULT_PARSER_FEATURE);
}
public JSONScanner(char[] input, int inputLength, int features){
this.features = features;
SoftReference<char[]> sbufRef = sbufRefLocal.get();
if (sbufRef != null) {
sbuf = sbufRef.get();
sbufRefLocal.set(null);
}
if (sbuf == null) {
sbuf = new char[64];
}
eofPos = inputLength;
if (inputLength == input.length) {
if (input.length > 0 && isWhitespace(input[input.length - 1])) {
inputLength--;
} else {
char[] newInput = new char[inputLength + 1];
System.arraycopy(input, 0, newInput, 0, input.length);
input = newInput;
}
}
buf = input;
buflen = inputLength;
buf[buflen] = EOI;
bp = -1;
ch = buf[++bp];
}
public boolean isResetFlag() {
return resetFlag;
}
public void setResetFlag(boolean resetFlag) {
this.resetFlag = resetFlag;
}
public final int getBufferPosition() {
return bp;
}
public void reset(int mark, char mark_ch, int token) {
this.bp = mark;
this.ch = mark_ch;
this.token = token;
resetFlag = true;
resetCount++;
}
public boolean isBlankInput() {
for (int i = 0; i < buflen; ++i) {
if (!isWhitespace(buf[i])) {
return false;
}
}
return true;
}
public static final boolean isWhitespace(char ch) {
// 专门调整了判断顺序
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || ch == '\b';
}
/**
* Report an error at the current token position using the provided arguments.
*/
private void lexError(String key, Object... args) {
token = ERROR;
}
/**
* Return the current token, set by nextToken().
*/
public final int token() {
return token;
}
public final String tokenName() {
return JSONToken.name(token);
}
private static boolean[] whitespaceFlags = new boolean[256];
static {
whitespaceFlags[' '] = true;
whitespaceFlags['\n'] = true;
whitespaceFlags['\r'] = true;
whitespaceFlags['\t'] = true;
whitespaceFlags['\f'] = true;
whitespaceFlags['\b'] = true;
}
public final void skipWhitespace() {
for (;;) {
if (whitespaceFlags[ch]) {
ch = buf[++bp];
continue;
} else {
break;
}
}
}
public final char getCurrent() {
return ch;
}
public final void nextTokenWithColon() {
for (;;) {
if (ch == ':') {
ch = buf[++bp];
nextToken();
return;
}
if (ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t' || ch == '\f' || ch == '\b') {
ch = buf[++bp];
continue;
}
throw new JSONException("not match ':' - " + ch);
}
}
public final void nextTokenWithColon(int expect) {
for (;;) {
if (ch == ':') {
ch = buf[++bp];
break;
}
if (isWhitespace(ch)) {
ch = buf[++bp];
continue;
}
throw new JSONException("not match ':', actual " + ch);
}
for (;;) {
if (expect == JSONToken.LITERAL_INT) {
if (ch >= '0' && ch <= '9') {
sp = 0;
pos = bp;
scanNumber();
return;
}
if (ch == '"') {
sp = 0;
pos = bp;
scanString();
return;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
1、TestDemo为android客户端代码 2、testJson为服务器端代码,需要Tomcat服务器 3、fastjson-1.1.25-android-javadoc fastjson的api 4、fastjson-1.1.25-sources fastjson的源码 5、Gson_javadocs Gson的api 6、gson-2.2.2-sources Gson的源码 启动Tomcat服务器之后运行客户端代码,在操作时注意看控制台的输出结果
资源推荐
资源详情
资源评论
收起资源包目录
很全的JSON数据解析 详细介绍fastJSON与Gson的使用和区别 还有详细demo (729个子文件)
com.alibaba.fastjson.serializer.AutowiredObjectSerializer 0B
jarlist.cache 120B
MainActivity.class 5KB
JsonServlet.class 3KB
InitDataService.class 2KB
FastJsonUtils.class 2KB
GsonUtils.class 2KB
HttpDataUtils.class 1KB
Person.class 1KB
Person.class 1KB
MainActivity$1.class 1KB
R.class 713B
R$string.class 665B
FastJsonUtils$1.class 648B
GsonUtils$3.class 630B
GsonUtils$1.class 594B
R$id.class 581B
GsonUtils$2.class 577B
FastJsonUtils.class 527B
JsonUtils.class 516B
Constants.class 492B
R$dimen.class 487B
Constants.class 482B
R$drawable.class 459B
R$layout.class 415B
R$menu.class 409B
R$style.class 407B
BuildConfig.class 353B
R$attr.class 352B
.classpath 630B
.classpath 529B
org.eclipse.wst.common.component 462B
org.eclipse.wst.jsdt.ui.superType.container 49B
stylesheet.css 1KB
stylesheet.css 1KB
inherit.gif 57B
inherit.gif 57B
index-all.html 343KB
index-all.html 93KB
JSONArray.html 84KB
DefaultJSONParser.html 81KB
JSONObject.html 73KB
Gson.html 71KB
JSON.html 67KB
JSONSerializer.html 67KB
DefaultJSONParser.html 60KB
JSONScanner.html 55KB
GsonBuilder.html 54KB
JSONSerializer.html 52KB
overview-tree.html 49KB
SerializeWriter.html 48KB
FilterUtils.html 45KB
TypeUtils.html 44KB
JsonElement.html 43KB
JsonReader.html 43KB
JsonArray.html 42KB
JsonWriter.html 41KB
ParserConfig.html 39KB
JsonPrimitive.html 35KB
FieldInfo.html 34KB
ParserConfig.html 32KB
JsonObject.html 32KB
SerializerFeature.html 31KB
TypeAdapter.html 31KB
ObjectDeserializer.html 31KB
JsonElement.html 29KB
FieldInfo.html 29KB
JavaBeanDeserializer.html 28KB
DeserializeBeanInfo.html 28KB
DefaultObjectDeserializer.html 27KB
JSONToken.html 25KB
package-tree.html 25KB
Feature.html 25KB
Feature.html 25KB
FieldDeserializer.html 24KB
constant-values.html 24KB
DefaultExtJSONParser.html 24KB
package-tree.html 24KB
ObjectSerializer.html 24KB
JsonToken.html 23KB
FieldNamingPolicy.html 23KB
TypeToken.html 23KB
GsonBuilder.html 22KB
allclasses-frame.html 21KB
FieldDeserializer.html 21KB
FieldSerializer.html 21KB
SerializerFeature.html 21KB
JavaBeanSerializer.html 21KB
FieldAttributes.html 20KB
ListResolveFieldDeserializer.html 20KB
ArrayListTypeFieldDeserializer.html 20KB
MapResolveFieldDeserializer.html 19KB
LongSerializationPolicy.html 19KB
package-use.html 19KB
Base64.html 19KB
package-use.html 19KB
allclasses-noframe.html 19KB
package-summary.html 19KB
JsonParseException.html 19KB
JsonStreamParser.html 19KB
共 729 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
shanshan421104
- 粉丝: 0
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页