package org.json;
/*
Copyright (c) 2002 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.text.ParseException;
/**
* A JSONObject is an unordered collection of name/value pairs. Its
* external form is a string wrapped in curly braces with colons between the
* names and values, and commas between the values and names. The internal form
* is an object having get() and opt() methods for accessing the values by name,
* and put() methods for adding or replacing values by name. The values can be
* any of these types: Boolean, JSONArray, JSONObject, Number, String, or the
* JSONObject.NULL object.
* <p>
* The constructor can convert an external form string into an internal form
* Java object. The toString() method creates an external form string.
* <p>
* A get() method returns a value if one can be found, and throws an exception
* if one cannot be found. An opt() method returns a default value instead of
* throwing an exception, and so is useful for obtaining optional values.
* <p>
* The generic get() and opt() methods return an object, which you can cast or
* query for type. There are also typed get() and opt() methods that do type
* checking and type coersion for you.
* <p>
* The texts produced by the toString() methods are very strict.
* The constructors are more forgiving in the texts they will accept:
* <ul>
* <li>An extra <code>,</code> <small>(comma)</small> may appear just
* before the closing brace.</li>
* <li>Strings may be quoted with <code>'</code> <small>(single
* quote)</small>.</li>
* <li>Strings do not need to be quoted at all if they do not begin with a quote
* or single quote, and if they do not contain leading or trailing spaces,
* and if they do not contain any of these characters:
* <code>{ } [ ] / \ : , = ; #</code> and if they do not look like numbers
* and if they are not the reserved words <code>true</code>,
* <code>false</code>, or <code>null</code>.</li>
* <li>Keys can be followed by <code>=</code> or <code>=></code> as well as
* by <code>:</code></li>
* <li>Values can be followed by <code>;</code> as well as by <code>,</code></li>
* <li>Numbers may have the <code>0-</code> <small>(octal)</small> or
* <code>0x-</code> <small>(hex)</small> prefix.</li>
* <li>Line comments can begin with <code>#</code></li>
* </ul>
* @author JSON.org
* @version 1
*/
public class JSONObject {
/**
* JSONObject.NULL is equivalent to the value that JavaScript calls null,
* whilst Java's null is equivalent to the value that JavaScript calls
* undefined.
*/
private static final class Null {
/**
* Make a Null object.
*/
private Null() {
}
/**
* There is only intended to be a single instance of the NULL object,
* so the clone method returns itself.
* @return NULL.
*/
protected final Object clone() {
return this;
}
/**
* A Null object is equal to the null value and to itself.
* @param object An object to test for nullness.
* @return true if the object parameter is the JSONObject.NULL object
* or null.
*/
public boolean equals(Object object) {
return object == null || object == this;
}
/**
* Get the "null" string value.
* @return The string "null".
*/
public String toString() {
return "null";
}
}
/**
* The hash map where the JSONObject's properties are kept.
*/
private HashMap myHashMap;
/**
* It is sometimes more convenient and less ambiguous to have a NULL
* object than to use Java's null value.
* JSONObject.NULL.equals(null) returns true.
* JSONObject.NULL.toString() returns "null".
*/
public static final Object NULL = new Null();
/**
* Construct an empty JSONObject.
*/
public JSONObject() {
myHashMap = new HashMap();
}
/**
* Construct a JSONObject from a JSONTokener.
* @throws ParseException if there is a syntax error in the source string.
* @param x A JSONTokener object containing the source string.
*/
public JSONObject(JSONTokener x) throws ParseException {
this();
char c;
String key;
if (x.nextClean() != '{') {
throw x.syntaxError("A JSONObject must begin with '{'");
}
while (true) {
c = x.nextClean();
switch (c) {
case 0:
throw x.syntaxError("A JSONObject must end with '}'");
case '}':
return;
default:
x.back();
key = x.nextValue().toString();
}
c = x.nextClean();
if (c == '=') {
if (x.next() != '>') {
x.back();
}
} else if (c != ':') {
throw x.syntaxError("Expected a ':' after a key");
}
myHashMap.put(key, x.nextValue());
switch (x.nextClean()) {
case ';':
case ',':
if (x.nextClean() == '}') {
return;
}
x.back();
break;
case '}':
return;
default:
throw x.syntaxError("Expected a ',' or '}'");
}
}
}
/**
* Construct a JSONObject from a string.
* @exception ParseException The string must be properly formatted.
* @param string A string beginning
* with <code>{</code> <small>(left brace)</small> and ending
* with <code>}</code> <small>(right brace)</small>.
*/
public JSONObject(String string) throws ParseException {
this(new JSONTokener(string));
}
/**
* Construct a JSONObject from a Map.
* @param map A map object that can be used to initialize the contents of
* the JSONObject.
*/
public JSONObject(Map map) {
myHashMap = new HashMap(map);
}
/**
* Accumulate values under a key. It is similar to the put method except
* that if there is already an object stored under the key then a
* JSONArray is stored under the key to hold all of the accumulated values.
* If there is already a JSONArray, then the new value is appended to it.
* In contrast, the put method replaces the previous value.
* @throws NullPointerException if the key is null
* @param key A key string.
* @param value An object to be accumulated under the key.
* @return this.
*/
public JSONObject accumulate(String key, Object value)
throws NullPointerException {
JSONArray a;
Object o = opt(k
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码ajax 学习笔记源代码
资源详情
资源评论
资源推荐
收起资源包目录





































































































共 102 条
- 1
- 2

















云计算-魏军
- 粉丝: 133
上传资源 快速赚钱
我的内容管理 展开
我的资源 快来上传第一个资源
我的收益
登录查看自己的收益我的积分 登录查看自己的积分
我的C币 登录后查看C币余额
我的收藏
我的下载
下载帮助


最新资源
- 使用airtest开发的闪耀!优俊少女(赛马娘国服)自动化培育脚本,使用ai图像识别方案脚本方案,无需root
- Furion-C#资源
- Ingenious 工作流引擎-PHP资源
- pdfh5-JavaScript资源
- websql-SQL资源
- Demo-计算机二级资源
- OJCode-ACM资源
- my_project-大创资源
- vcos_components-智能车资源
- lanqiaobei-web-蓝桥杯资源
- 优亿智能算法平台,包括了各类常用的算法模块,比如图像识别、本文分类、推荐系统等,为各类常用的场景提供算法模型
- 汇编语言-汇编语言资源
- ascendc-api-adv-C语言资源
- ZKMALL-B2B2C多商户电商Java商城后台-C++资源
- J2Cache-Java资源
- 绿地识别,简单的图像分割项目
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



安全验证
文档复制为VIP权益,开通VIP直接复制

评论2