package org.json;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.io.StringWriter;
import junit.framework.TestCase;
/*
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.
*/
/**
* Test class. This file is not formally a member of the org.json library.
* It is just a test tool.
*
* Issue: JSONObject does not specify the ordering of keys, so simple-minded
* comparisons of .toString to a string literal are likely to fail.
*
* @author JSON.org
* @version 2011-10-25
*/
public class Test extends TestCase {
public Test(String name) {
super(name);
}
protected void setUp() throws Exception {
super.setUp();
}
protected void tearDown() throws Exception {
super.tearDown();
}
public void testXML() throws Exception {
JSONObject jsonobject;
String string;
jsonobject = XML.toJSONObject("<![CDATA[This is a collection of test patterns and examples for org.json.]]> Ignore the stuff past the end. ");
assertEquals("{\"content\":\"This is a collection of test patterns and examples for org.json.\"}", jsonobject.toString());
assertEquals("This is a collection of test patterns and examples for org.json.", jsonobject.getString("content"));
string = "<test><blank></blank><empty/></test>";
jsonobject = XML.toJSONObject(string);
assertEquals("{\"test\": {\n \"blank\": \"\",\n \"empty\": \"\"\n}}", jsonobject.toString(2));
assertEquals("<test><blank/><empty/></test>", XML.toString(jsonobject));
string = "<subsonic-response><playlists><playlist id=\"476c65652e6d3375\" int=\"12345678901234567890123456789012345678901234567890213991133777039355058536718668104339937\"/><playlist id=\"50617274792e78737066\"/></playlists></subsonic-response>";
jsonobject = XML.toJSONObject(string);
assertEquals("{\"subsonic-response\":{\"playlists\":{\"playlist\":[{\"id\":\"476c65652e6d3375\",\"int\":\"12345678901234567890123456789012345678901234567890213991133777039355058536718668104339937\"},{\"id\":\"50617274792e78737066\"}]}}}", jsonobject.toString());
}
public void testNull() throws Exception {
JSONObject jsonobject;
jsonobject = new JSONObject("{\"message\":\"null\"}");
assertFalse(jsonobject.isNull("message"));
assertEquals("null", jsonobject.getString("message"));
jsonobject = new JSONObject("{\"message\":null}");
assertTrue(jsonobject.isNull("message"));
}
public void testJSON() throws Exception {
double eps = 2.220446049250313e-16;
Iterator iterator;
JSONArray jsonarray;
JSONObject jsonobject;
JSONStringer jsonstringer;
Object object;
String string;
Beany beanie = new Beany("A beany object", 42, true);
string = "[001122334455]";
jsonarray = new JSONArray(string);
assertEquals("[1122334455]", jsonarray.toString());
string = "[666e666]";
jsonarray = new JSONArray(string);
assertEquals("[\"666e666\"]", jsonarray.toString());
string = "[00.10]";
jsonarray = new JSONArray(string);
assertEquals("[0.1]", jsonarray.toString());
jsonobject = new JSONObject();
object = null;
jsonobject.put("booga", object);
jsonobject.put("wooga", JSONObject.NULL);
assertEquals("{\"wooga\":null}", jsonobject.toString());
assertTrue(jsonobject.isNull("booga"));
jsonobject = new JSONObject();
jsonobject.increment("two");
jsonobject.increment("two");
assertEquals("{\"two\":2}", jsonobject.toString());
assertEquals(2, jsonobject.getInt("two"));
string = "{ \"list of lists\" : [ [1, 2, 3], [4, 5, 6], ] }";
jsonobject = new JSONObject(string);
assertEquals("{\"list of lists\": [\n" +
" [\n" +
" 1,\n" +
" 2,\n" +
" 3\n" +
" ],\n" +
" [\n" +
" 4,\n" +
" 5,\n" +
" 6\n" +
" ]\n" +
"]}", jsonobject.toString(4));
assertEquals("<list of lists><array>1</array><array>2</array><array>3</array></list of lists><list of lists><array>4</array><array>5</array><array>6</array></list of lists>",
XML.toString(jsonobject));
string = "<recipe name=\"bread\" prep_time=\"5 mins\" cook_time=\"3 hours\"> <title>Basic bread</title> <ingredient amount=\"8\" unit=\"dL\">Flour</ingredient> <ingredient amount=\"10\" unit=\"grams\">Yeast</ingredient> <ingredient amount=\"4\" unit=\"dL\" state=\"warm\">Water</ingredient> <ingredient amount=\"1\" unit=\"teaspoon\">Salt</ingredient> <instructions> <step>Mix all ingredients together.</step> <step>Knead thoroughly.</step> <step>Cover with a cloth, and leave for one hour in warm room.</step> <step>Knead again.</step> <step>Place in a bread baking tin.</step> <step>Cover with a cloth, and leave for one hour in warm room.</step> <step>Bake in the oven at 180(degrees)C for 30 minutes.</step> </instructions> </recipe> ";
jsonobject = XML.toJSONObject(string);
assertEquals("{\"recipe\": {\n \"title\": \"Basic bread\",\n \"cook_time\": \"3 hours\",\n \"instructions\": {\"step\": [\n \"Mix all ingredients together.\",\n \"Knead thoroughly.\",\n \"Cover with a cloth, and leave for one hour in warm room.\",\n \"Knead again.\",\n \"Place in a bread baking tin.\",\n \"Cover with a cloth, and leave for one hour in warm room.\",\n \"Bake in the oven at 180(degrees)C for 30 minutes.\"\n ]},\n \"name\": \"bread\",\n \"ingredient\": [\n {\n \"content\": \"Flour\",\n \"amount\": 8,\n \"unit\": \"dL\"\n },\n {\n \"content\": \"Yeast\",\n \"amount\": 10,\n \"unit\": \"grams\"\n },\n {\n \"content\": \"Water\",\n \"amount\": 4,\n \"unit\": \"dL\",\n \"state\": \"warm\"\n },\n {\n \"content\": \"Salt\",\n \"amount\": 1,\n \"unit\": \"teaspoon\"\n }\n ],\n \"prep_time\": \"5 mins\"\n}}",
jsonobject.toString(4));
jsonobject = JSONML.toJSONObject(string);
assertEquals("{\"cook_time\":\"3 hours\",\"name\":\"bread\",\"tagName\":\"recipe\",\"childNodes\":[{\"tagName\":\"title\",\"childNodes\":[\"Basic bread\"]},{\"amount\":8,\"unit\":\"dL\",\"tagName\":\"ingredient\",\"childNodes\":[\"Flour\"]},{\"amount\":10,\"unit\":\"grams\",\"tagName\":\"ingredient\",\"childNodes\":[\"Yeast\"]},{\"amount\":4,\"unit\":\"dL\",
没有合适的资源?快使用搜索试试~ 我知道了~
xinwen.zip_手机
共269个文件
png:102个
class:65个
java:45个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 116 浏览量
2022-09-14
20:40:04
上传
评论
收藏 1.48MB ZIP 举报
温馨提示
仿百度新闻系统,手机端和服务器端源码,自己花了不少时间写的
资源推荐
资源详情
资源评论
收起资源包目录
xinwen.zip_手机 (269个子文件)
all-wcprops 514B
resources.ap_ 122KB
RuoshuiNews.apk 142KB
proguard.cfg 1KB
Test.class 51KB
JSONObject.class 19KB
JSONArray.class 11KB
MainActivity.class 10KB
NewsDetailsActivity.class 8KB
XML.class 7KB
JSONML.class 6KB
JSONTokener.class 6KB
SyncHttp.class 4KB
XMLTokener.class 4KB
GetCategoriesServlet.class 4KB
GetSpecifyCategoryNewsServlet.class 4KB
CDL.class 4KB
GetCommentsServlet.class 4KB
JSONWriter.class 4KB
SqlManager.class 4KB
GetNewsServlet.class 3KB
CommentDAO.class 3KB
Cookie.class 3KB
MainActivity$2.class 3KB
NewsDAO.class 3KB
R$id.class 3KB
News.class 3KB
PostCommentServlet.class 3KB
MainActivity$LoadNewsAsyncTask.class 3KB
HTTP.class 2KB
CategoryDAO.class 2KB
R$drawable.class 2KB
TextUtility.class 2KB
Comment.class 2KB
Parameter.class 2KB
MainActivity$4.class 2KB
Test$Beany.class 2KB
CommentsActivity.class 2KB
CookieList.class 2KB
CategoryDAOTest.class 2KB
MainActivity$1.class 2KB
UserDAO.class 1KB
Category.class 1KB
ReplayDAOTest.class 1KB
NewsDetailsActivity$UpdateNewsThread.class 1KB
CustomSimpleAdapter.class 1KB
NewsDetailsActivity$NewsBodyOnTouchListener.class 1KB
NewsDetailsActivity$NewsDetailsTitleBarOnClickListener.class 1KB
Category.class 1KB
NewsDetailsActivity$1.class 1KB
MainActivity$3.class 1KB
UserDAOTest.class 1KB
HTTPTokener.class 1019B
NewsDAOTest.class 908B
DensityUtil.class 859B
JSONObject$Null.class 768B
R.class 754B
JSONException.class 747B
R$color.class 712B
StringUtil.class 705B
R$layout.class 687B
R$string.class 687B
JSONStringer.class 553B
R$anim.class 517B
R$style.class 416B
R$array.class 406B
BuildConfig.class 351B
R$attr.class 349B
JSONString.class 156B
.classpath 566B
.classpath 288B
classes.dex 31KB
entries 854B
mysql-connector-java-5.1.6-bin.jar 687KB
junit.jar 114KB
Test.java 70KB
JSONObject.java 54KB
JSONArray.java 29KB
XML.java 17KB
JSONML.java 15KB
JSONTokener.java 13KB
MainActivity.java 11KB
XMLTokener.java 11KB
JSONWriter.java 10KB
CDL.java 10KB
R.java 9KB
NewsDetailsActivity.java 8KB
Cookie.java 7KB
HTTP.java 6KB
SqlManager.java 5KB
SyncHttp.java 4KB
GetCategoriesServlet.java 4KB
CookieList.java 3KB
JSONStringer.java 3KB
GetSpecifyCategoryNewsServlet.java 3KB
GetCommentsServlet.java 3KB
HTTPTokener.java 2KB
CommentDAO.java 2KB
GetNewsServlet.java 2KB
NewsDAO.java 2KB
共 269 条
- 1
- 2
- 3
资源评论
周楷雯
- 粉丝: 80
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功