The JSON is a lightweight, text-based and language-independent data exchange format. The JSON can represent two structured types like objects and arrays. A JSONArray can parse text from a String to produce a vector-like object. We can parse a nested JSON object using the getString(index) method of JSONArray. This is a convenience method for the getJSONString(index).getString() method and it returns a string value at the specified position.
Syntax
String getString(int index)
登录后复制
Example
import java.util.*;import org.json.*;public class NestedJSONObjectTest { public static void main(String args[]) { String jsonDataString = "{userInfo : [{username:abc123}, {username:xyz123},{username:pqr123}, {username:mno123},{username:jkl123}]}"; JSONObject jsonObject = new JSONObject(jsonDataString); List list = new ArrayList(); JSONArray jsonArray = jsonObject.getJSONArray("userInfo"); for(int i = 0 ; iOutput
abc123xyz123pqr123mno123jkl123登录后复制
以上就是我们如何在Java中解析嵌套的JSON对象?的详细内容,更多请关注【创想鸟】其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至253000106@qq.com举报,一经查实,本站将立刻删除。
发布者:PHP中文网,转转请注明出处:https://www.chuangxiangniao.com/p/3041858.html