org.json.JSONObject的getString和optString使用注意事项
结论:org.json.JSONObject的getString如果取不到对应的key会抛出异常,optString则不会
/**
* Returns the value mapped by {@code name} if it exists, coercing it if
* necessary, or throws if no such mapping exists.
*
* @throws JSONException if no such mapping exists.
*/
public String getString(String name) throws JSONException {
Object object = get(name);
String result = JSON.toString(object);
if (result == null) {
throw JSON.typeMismatch(name, object, "String");
}
return result;
} /**
* Returns the value mapped by {@code name} if it exists, coercing it if
* necessary, or the empty string if no such mapping exists.
*/
public String optString(String name) {
return optString(name, "");
}
org.json.JSONObject的getString和optString使用注意事项的更多相关文章
- jsonobject 遍历 org.json.JSONObject
import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public static ...
- net.sf.json.JSONObject 和org.json.JSONObject 的差别
http://my.oschina.net/wangwu91/blog/340721 net.sf.json.JSONObject 和org.json.JSONObject 的差别. 一.创建jso ...
- java.lang.ClassCastException: net.sf.json.JSONNull cannot be cast to net.sf.json.JSONObject的解决方法
报错情况已经说明了,在百度查了好几个解决方法,这里总结一下: 首先:加一个判断是否为空,再做操作 // 得到json串 String jsonString = UtilPOSTGET.UPost(FO ...
- net.sf.json.JSONOBJECT.fromObject 与 com.alibaba.fastjson.JSONObject.parseObject
文章待补充,先写写以下知识点好了. NULL值处理之 net.sf.json.JSONObject 和 com.alibaba.fastjson.JSONObject区别 JSON作为一个轻量级的文本 ...
- [转]json+JSONObject+JSONArray 结合使用
JSONObject与JSONArray的区别简述: 区别在于JSONObject是一个{}包裹起来的一个对象(Object),而JSONArray则是[]包裹起来的一个数组(Array),说白点就是 ...
- Jmeter not found in class'org.json.JSONObject 问题
前景:公司有银行的项目要进行压测,但是接口有近视RSA加密,需发送签名,只能使用java编写原生接口脚本打包成jar使用BeanShell Sampler去调用发送请求.在使用的过程中遇到了如下问题. ...
- 使用JSONObject遇到的问题,java.lang.NoClassDefFoundError: net/sf/json/JSONObject
先是报 java.lang.NoClassDefFoundError: net/sf/json/JSONObject 这个错误, 打开项目属性找到java build path中的libaries,找 ...
- Sqoop异常:Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONObject
18/12/07 01:09:03 INFO mapreduce.ImportJobBase: Beginning import of staffException in thread "m ...
- sqoop执行job报错(org/json/JSONObject)
NoClassDefFoundError: org/json/JSONObject: [root@hadoop2 ~]# sqoop job --create myjob7 -- import -- ...
随机推荐
- Redis的两种持久化方式详细介绍
一,Redis是一款基于内存的数据库,可以持久化,在企业中常用于缓存,相信大家都比较熟悉Redis了,下面主要分享下关于Redis持久化的两种模式 1.半持久化模式(RDB,filesnapshott ...
- SPOJ DIVCNT2
SPOJ DIVCNT2 题目大意: 求\(S2(n)=\sum_{i=1}^{n}\sigma_0{(i^2)}\) . 题解 我们可以先考虑括号里只有一个\(i\)的情况,这样,我们把\(i\)分 ...
- 解决pgpool启动报错 ifup[/sbin/ip] doesn't have setuid bit
1.问题出现: 在centos7启动pgpool服务器报错ifup[/sbin/ip] doesn't have setuid bit 2018-11-25 01:14:14: pid 38122: ...
- HTML界面多语言切换
我在做个人网站时考虑到多语言转换的问题,最后在JS文件中将所有文字数据储存然后设置HTML中的class与key属性来达到多语言效果.当然,还有一个别的方法,就是所有有文字内容的div都用不同语言写一 ...
- 关于Python常见功能使用的博客收藏
Python绘制曲面和曲面对应的等高线图: https://blog.csdn.net/weixin_40198632/article/details/78570679 python实现三维拟合 ht ...
- Mysql 根据一个表数据更新另外一个表
方法一: update 更新表 set 字段 = (select 参考数据 from 参考表 where 参考表.id = 更新表.id); update table_2 m set m.colum ...
- matplotlib库的简单应用
matplotlib库 import matplotlib.pyplot as plt import matplotlib matplotlib.rcParams['font.family']='Si ...
- CSS部分语法2
<!-- 第1部分 尺寸与框模型 略 第2部分背景设置 2.1 背景颜色:background-color:value 2.2 背景图片:background-image body{ backg ...
- JSP循环缓存列表
两种方法: 例如,有下拉框 <select></select>其中选项需要循环显示 1.JAVA代码循环 <% for(int i=0;i<list.size(); ...
- 【题解】魔板—洛谷P1275。
话说好久没更博了. 最近学了好多知识懒的加进来了. 有幸认识一位大佬. 让我有了继续更博的兴趣. 但这是一个旧的题解. 我在某谷上早就发过的. 拿过来直接用就当回归了吧. 其实这道题有一个特别关键的思 ...