前解析json已使用get方法,但是,假设抛出将解决很烦人中断。

今天发现JSONObject还提供了一个更好用的方法opt。看来以后文档还是要更加认真的读的。以下是文档中的原文。

A JSONObject constructor can be used to convert an external form JSON text into an internal form whose values can be retrieved with the get and opt methods,
or to convert values into a JSON text using the put and toString methods. 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.

详见:http://www.json.org/javadoc/org/json/JSONObject.html

版权声明:本文博客原创文章,博客,未经同意,不得转载。

JSONObject 解析的更多相关文章

  1. 使用JsonObject解析json

    第一种: [ { "0": "1", "1": "一", "id": "1", ...

  2. 【Unity】使用JSONObject解析Json

    为何要用JSONObject 之前已经用过JsonUtility和Newton.Json来解析Json了,为什么现在又要用一个新的JSONObject来解析Json? 使用JsonUtility:ht ...

  3. JSON初体验(一):JsonObject解析

    在学校的呆了一段时间,马上又要回去工作了,不说了,我现在介绍一下json相关的内容 1.JSON数据格式(总的来说,json就是一个字符串) 1.整体结构 String json1 = "{ ...

  4. $Java-json系列(二):用JSONObject解析和处理json数据

    本文中主要介绍JSONObject处理json数据时候的一些常用场景和方法. (一)jar包下载 所需jar包打包下载百度网盘地址:https://pan.baidu.com/s/1c27Uyre ( ...

  5. [Android]JsonObject解析

    android和服务器进行交互的时候往往会有数据的传输,而数据中有一种类型就是Json型,这两天在研究API接口的问题,服务器返回的数据类型都是Json型的.例如: 1.接收到的json字符串分为两种 ...

  6. 用JSONObject解析和处理json数据

    (一)jar包下载 所需jar包打包下载百度网盘地址:https://pan.baidu.com/s/1c27Uyre (二)常见场景及处理方法 1.解析简单的json字符串: 1 // 简单的jso ...

  7. JSON(2)JSONObject解析Josn和创建Jsonf示例

    1.解析Json /* * test.josn内容如下: { "languages":[ {"id":"1","name" ...

  8. JSONObject解析json数据

    首先先看一下我们要解析的json数据是什么样子的: 代码: String url="http://113.57.190.228:8001/Web/Report/GetBigMSKReport ...

  9. 浅谈JSONObject解析JSON数据

    我们在做jmeter接口测试时能会用beanshell断言,一般都会将返回值转成JSONObject对象进行处理.本文选取较为复杂json格式数据,也将适用于java接口测试. JSON数据 { &q ...

随机推荐

  1. 【77.78%】【codeforces 625C】K-special Tables

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  2. [Recompose] Render Nothing in Place of a Component using Recompose

    Learn how to use the ‘branch’ and ‘renderNothing’ higher-ordercomponents to render nothing when a ce ...

  3. ios开发runtime学习四:动态添加属性

    #import "ViewController.h" #import "Person.h" #import "NSObject+Property.h& ...

  4. 访问sharepoint站点自动使用当前用户名和密码登录

    https://blog.csdn.net/zw_2011/article/details/7417123 1.把sharepoint站点添入可信站点.   点击菜单栏“工具”——〉“Internet ...

  5. Spring-boot更改成war包的方式

    转载至:  https://blog.csdn.net/zhuwei_clark/article/details/82114102  Step1 修改启动类 Step2 修改配置文件为properti ...

  6. [Vue] Create Filters in Vue.js

    Just like in the command line, you can pipe a property through a filter to get a desired result. You ...

  7. PatentTips - OpenCL compilation

    BACKGROUND The present disclosure relates generally to integrated circuits, such as field programmab ...

  8. 微信小程序从零开始开发步骤(一)

    从零到有写一个小程序系列专题,很早以前就想写来分享,但由于项目一直在进展,没有过多的时间研究技术,现在可以继续分享了.1:注册用没有注册过微信公众平台的邮箱注册一个微信公众号, 申请帐号 ,点击 ht ...

  9. Python 数组[],元组(),字典{}的异同

    序列 Python有6中内建的序列,在这里我们重点讨论两种,数组和元组.所有序列都可以做某些特定的操作,大致上常用的是:加,乘,索引,分片以及检查某个元素是否属于序列的成员. Python还提供一些内 ...

  10. Java相关思维导图分享

    非常多朋友都给我发私信希望获得一份Java知识的思维导图,我来不及一一答复.原先是给大家一个百度网盘的链接分享,大家能够自己去下载,可是不知道云盘还能用多久.把相关资源转移到了QQ的群共享中.须要的朋 ...