Java学习-030-JSON 之四 -- 判断 JSONObject 是否包含键值对
前文对获取 JSON 数据封装方法,使之可通过类似于 cssSelector 的方法获取 JSON 数据,使获取数据变得简单。敬请参阅:模仿 cssSelector 封装读取 JSON 数据方法。
在日常的测试中,需要验证 JSON 数据中某一个值是否正确,再次封装一个方法,验证 JSONObject 中是否包含特定的键值。
直接上码了:
/**
* Aaron.ffp Inc.
* Copyright (c) 2004-2015 All Rights Reserved.
*/
package com.demo; import java.io.IOException; import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.helper.StringUtil;
import org.jsoup.nodes.Document;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import org.testng.log4testng.Logger; /**
*
* @author Aaron.ffp
* @version V1.0.0: Jsoup com.demo ITestHome.java, 2015-8-31 19:03:15 Exp $
*/
public class ITestHome {
private String request = "http://mb.51buy.com/json.php?mod=home&act=config";
private Logger logger = Logger.getLogger(this.getClass());
private String message = "";
private Document doc;
private String test; /**
* send request and get response
*
* @author Aaron.ffp
* @version V1.0.0: Jsoup com.demo ITestHome.java beforeTest, 2015-8-31 19:04:05 Exp $
*
* @throws IOException
*/
@BeforeTest
public void beforeTest() throws IOException{
this.doc = Jsoup.connect(this.request).data("appSource","android")
.userAgent("Jsoup demo")
.cookie("user", "Jsoup")
.timeout(5000).get();
this.test = doc.select("body").get(0).text();
} /**
*
*
* @author Aaron.ffp
* @version V1.0.0: Jsoup com.demo ITestHome.java test_isJSONObjectContainKV, 2015-9-2 20:24:56 Exp $
*
* @throws IOException
*/
@Test
public void test_isJSONObjectContainKV() throws IOException {
System.out.println("\n\n==================================== test_isJSONObjectContainKV"); System.out.println("errno --> " + this.isJSONObjectContainKV(new JSONObject(this.test), "errno:0"));
System.out.println("title:星星 --> " + this.isJSONObjectContainKV(new JSONObject(this.getJsonText(this.test, "$data|#floor|$1|#colmunInfo|$0")), "title:星星"));
} /**
* Assert the key-value exist or not in the JSONObject
*
* @author Aaron.ffp
* @version V1.0.0: Jsoup com.demo ITestHome.java isJSONObjectContainKV, 2015-9-2 20:05:18 Exp $
*
* @param jsonObject : JSONObject
* @param kv : key:value
*
* @return boolean
*/
public boolean isJSONObjectContainKV(JSONObject jsonObject, String key_value){
boolean flag = false; try{
if (jsonObject == null) {
new NullPointerException("The argument {" + jsonObject + "} is null, please check this!"); return flag;
} // assert key_value : null, empty, whitespace
if (StringUtil.isBlank(key_value) || !"2".equals(String.valueOf(key_value.split(":").length)) ||
StringUtil.isBlank(key_value.split(":")[0]) || StringUtil.isBlank(key_value.split(":")[1])) {
this.message = "The argument {" + key_value + "} is invalid, please check this!";
this.logger.warn(this.message); return flag;
} String act = jsonObject.get(key_value.split(":")[0]).toString();
String exp = key_value.split(":")[1]; // assert the actual value is expected or not
if (exp.equals(act)) {
flag = true;
}
} catch (JSONException je){
this.message = je.getMessage();
this.logger.error(this.message); return flag;
} return flag;
} /**
* Get JSON Object {JSONObject, JSONArray, text} by json selector
*
* @author Aaron.ffp
* @version V1.0.0: Jsoup com.demo ITestHome.java getJsonText, 2015-9-1 19:40:12 Exp $
*
* @param json : JSON string
* @param selector : JSON selector
* $key|$key|#array|#int|$int|key
* #key|#int
* $key|#key|$int
* key
*
* array|key : is illegal
* key|$ : is illegal
* key|# : is illegal
* key|key : is illegal
* @return
*/
public String getJsonText(String json, String selector){
JSONObject jo = null;
JSONArray ja = null;
String jsonText = "";
String item = "";
String flag = "O"; // O - JSONObject; A - JSONArray; T - text // arguments must not be null
if (json == null || selector == null) {
this.message = "The argument {" + json + "} and {" + selector + "} must be not null, please check this!";
this.logger.error(this.message); new IllegalArgumentException(this.message);
} // return empty if the json is empty
if ("".equals(json)) {
return "";
} // return json if the selector is empty
if ("".equals(selector)) {
return json;
} try{
jo = new JSONObject(json); String[] select = selector.split("\\|"); for (int i = 0; i < select.length; i++) {
item = select[i]; // throw exception when selector against the rule
if (flag.equals("T") || (flag.equals("A") && (!item.startsWith("O") || !item.startsWith("A") || !StringUtil.isNumeric(item.substring(1))))) {
new IllegalArgumentException("The argument {" + selector + "} is invalid to the define rule of selector, please check this!");
} if (item.startsWith("#")) { // get JSONArray
if (flag.equals("A")) {
ja = ja.getJSONArray(Integer.valueOf(item.substring(1)));
} else if (flag.equals("O")){
ja = jo.getJSONArray(item.substring(1));
} flag = "A";
} else if (item.startsWith("$")){ // get JSONObject
if (flag.equals("O")) {
jo = jo.getJSONObject(item.substring(1));
} else if (flag.equals("A")){
jo = ja.getJSONObject(Integer.valueOf(item.substring(1)));
} flag = "O";
} else { // get text
jsonText = jo.get(item).toString(); flag = "T";
}
}
} catch (JSONException jsone){
jsone.printStackTrace();
} switch (flag) {
case "O":
return jo.toString();
case "A":
return ja.toString();
default:
return jsonText;
}
}
}
运行结果如下图所示:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAmYAAAEuCAIAAACrrUlBAAAVTUlEQVR4nO3dzZWruNoG0ArpjgmISL4AiIbRDeFmwLAHncKZ+RtggwSS/OKfwlVn78Va3SVAgKjDY2EKfY3//d8FAKj48+fPP//88++//36N//3ff/7vPyaTyWQymWqTyDSZTCaTKTSJTJPJZDKZQlMhMs++XQwAH0RkAkCIyASAEJEJACEiEwBCRCYAhIhMAAgRmQAQIjIBIERkAkCIyAS2xv6rG6bo0tPQfaX68XK5XC5rad/33ZBWfnUrnEvmLa6V5XN3Jc0dnIbuthsvl+7PNHTv2kxl05HzkrVhcnZu/9OPm4XCpxqRCR/qVVfjb7uqp/kxDd1yJR77PO1uC01Dl5R3XZfMuLd8Uv27FNttuz9fjyfzW89Lei6SfR7Tzy7v3odf6U5kbj8+3j6TKFeu/Pny6r/L3QrrhS2dtb38LeXdNXIa9dzb8n73CvXv1i1GZrZEvuLYX3dp7LthuP2wLFZffui6YSz0k9IDznag3m5pr/G617V2a3Yqk3XWxb++vvq+35S3zsu6N9n+F89Ltf5kT4cuO+tLA94aXQfzGL1M+FDFy3OaRGmvq9arq9XTtg+8Rv3pMumWkogt7OTlV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WUCQIhepnLlyk8uP/syCFF6mQAQIjIBIERkAkCIyASAEJEJACGtyDSZTCaTybSfRKbJZDKZTKFJZJpMJpPJFJrWyDz7XjEAfK4/f/6ITAC4T2QCQMgSmf8PLwEhlCumQzUAAAAASUVORK5CYII=" alt="" />
各位也可修改上述源码中的第 98 行,以满足不同方式的对比判断,例如:相等、包含、起始、结尾等。
至此, Java学习-030-JSON 之四 -- 判断 JSONObject 是否包含键值对 顺利完结,希望此文能够给初学 Java 的您一份参考。
最后,非常感谢亲的驻足,希望此文能对亲有所帮助。热烈欢迎亲一起探讨,共同进步。非常感谢! ^_^
Java学习-030-JSON 之四 -- 判断 JSONObject 是否包含键值对的更多相关文章
- Java学习-031-JSON 之五 -- 特定数据获取(JSONObject满足特定键值)
前面几篇博文分别讲述了 JSON 的 概要知识.简单数据获取.封装cssSelector数据获取方法.JSONObject 是否包含 key_value,请自行阅读相关博文. 在日常的接口测试脚本编写 ...
- java学习之JSON
0X00前言 JSON可以说是javascript的一种数据类型,我们学习JSON是为了在客户端的数据给读取出来,官方的解释是:概述:JSON(JavaScript Object Notation, ...
- Java学习之分支结构---判断语句:if语句和switch语句
一个if语句包含一个布尔表达式和一条或多条语句,if 语句的用语法如下:if 语句 if(布尔表达式) { //如果布尔表达式为true将执行的语句 },如果布尔表达式的值为 true,则执行 if ...
- JDBC学习笔记(6)——获取自动生成的主键值&处理Blob&数据库事务处理
获取数据库自动生成的主键 [孤立的技术是没有价值的],我们这里只是为了了解具体的实现步骤:我们在插入数据的时候,经常会需要获取我们插入的这一行数据对应的主键值. 具体的代码实现: /** * 获取数据 ...
- java解析出url请求的路径和参数键值对类 - 转
import java.util.HashMap; import java.util.Map; public class CRequest { /** * 解析出url请求的路径,包括页面 * @pa ...
- 【转】JDBC学习笔记(6)——获取自动生成的主键值&处理Blob&数据库事务处理
转自:http://www.cnblogs.com/ysw-go/ 获取数据库自动生成的主键 我们这里只是为了了解具体的实现步骤:我们在插入数据的时候,经常会需要获取我们插入的这一行数据对应的主键值. ...
- 【Java必修课】通过Value获取Map中的键值Key的四种方法
1 简介 我们都知道Map是存放键值对<Key,Value>的容器,知道了Key值,使用方法Map.get(key)能快速获取Value值.然而,有的时候我们需要反过来获取,知道Value ...
- Java学习笔记-Json
//先导入gson到lib,add build path //2015年5月5日22:02:37 package com.alfredsun.thread; import com.google.gso ...
- Java学习笔记——设计模式之四.代理模式
To be, or not to be: that is the question. --<哈姆雷特> 代理模式(Proxy),为其他对象提供一种代理以控制对这个对象的访问. 上代码: p ...
随机推荐
- webapp开发经验总结
webapp开发的大趋势之下,本人收集整理了一写关于webapp开发的经验,欢迎大家补充指正. 关于link <link rel="apple-touch-startup-image& ...
- NOIP 2002过河卒 Label:dp
题目描述 如图,A 点有一个过河卒,需要走到目标 B 点.卒行走规则:可以向下.或者向右.同时在棋盘上的任一点有一个对方的马(如上图的C点),该马所在的点和所有跳跃一步可达的点称为对方马的控制点.例如 ...
- 关于TbSchedule任务调度管理框架的整合部署
一.前言 任务调度管理作为基础架构通常会出现于我们的业务系统中,目的是让各种任务能够按计划有序执行.比如定时给用户发送邮件.将数据表中的数据同步到另一个数据表都是一个任务,这些相对耗时的操作通过任务调 ...
- Linux(Redhat)下redis安装
原文:http://www.javaweb1024.com/data/NoSQL/2015/06/29/785.html redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系 ...
- GetSystemMetrics()
GetSystemMetrics()函数的用法 可以用GetSystemMetrics函数可以获取系统分辨率,但这只是其功能之一,GetSystemMetrics函数只有一个参数,称之为「索引」,这个 ...
- android之发送短信程序
首先改写activity_main.xml文件 代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/re ...
- php根据IP地址跳转对应的城市,淘宝REST api调用地址直接使用
<?php // 定义一个函数getIP() function getIP(){ global $ip; if (getenv("HTTP_CLIENT_IP")) { $i ...
- Codeforces Round #360 (Div. 2) C D E
每次AB秒出 到了C难度陡然上升...翻译都弄不懂... C 给出一张图 找出两个点的覆盖集(覆盖集是指这图中每条边都有至少一个点在这个点集里面) 并且两个点集没有交集 英文很难看懂...就是二分图的 ...
- Mesa10.2在Win7上的编译
Mesa10仍然支持Windwos/linux,但是编译方式已经不提供makefile或者workspace Building on windows requires several open-sou ...
- Redis 笔记与总结4 set 和 zset 类型
(一)set 类型 set 是集合是 string 类型的无序集合. set 元素最大可以包含(2 的 32 次方)个元素.set 的是通过 hash table 实现的,所以添加.删除和查找的复杂度 ...