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 -- ...
随机推荐
- window.location.href 传参中文乱码问题!!!
不是所有地方都会用Ajax 当你使用window.location.href 来传中文参数的时候 如何避免乱码问题 js 是这样写的 下面代码中 方式 封装编码 参数 username ...
- 将图片转为base64
DEMO: <input type="file" id="file" multiple="multiple"> <div ...
- 用户认证授权和Shiro入门
1.权限管理基础(认证和授权): 前言 本文主要讲解的知识点有以下: 权限管理的基础知识 模型 粗粒度和细粒度的概念 回顾URL拦截的实现 Shiro的介绍与简单入门 一.Shiro基础知识 在学习S ...
- 配置rpm包安装的jdk环境变量
最近在搭建james邮件服务的时候,由于这个服务是用Java开发的,之前这台服务器跑过tomcat服务,故有Java环境,就没在意有无配置环境变量,但在启动james的时候报没有配置环境变量: 那么问 ...
- C# 类型转换的开销
先来个测试: static void Main(string[] args) { Stopwatch stopwatch; string strStr = "string"; ob ...
- django --视图装饰器
- P1972 [SDOI2009]HH的项链
洛谷的分块练习题 看到讨论中说分块莫队被卡就写了树状数组...(但感觉做法和莫队的思想有点像?) #include<bits/stdc++.h> using namespace std; ...
- 毕业设计——Django表单重复提交问题
1. 先记录一些正常情况:在填写表单页面(如注册.登录页面)时刷新页面时数据清空是正常的,此时就是重新发送了一个页面请求. 2. 问题一:用户登录后,刷新登陆后的页面(如首页)时会出现表单重复提交问题 ...
- gdb nnet3-compute
gdb nnet3-compute测试命令 $ matrix-dim 'scp: head -n 1 data/test/feats.scp|' ~/kaldi/src/bin/matrix-dim ...
- will not be managed by Spring/ [managed: 15; max: 15]
检查事务配置 检查 mybatis 配置文件扫描路径是否正确 <!-- 自动扫描 --> <context:component-scan base-package="com ...