第一种方法:

 String str = "{'array':[{'id':5,'name':'张三'},{'id':6,'name':'李四'}]}";
JSONArray jsonArray = null;
jsonArray = jsonobj.getJSONArray("array");//获取数组
System.out.println(jsonArray.getJSONObject(0).get("name"));
String str = "[{'columnId':5,'columnName':'人文历史'},{'columnId':2,'columnName':'商业视野'}]}";
JSONArray jsonArray = null;
jsonArray = new JSONArray(str);
System.out.println(jsonArray.getJSONObject(0).get("columnName"));

二、JAVA获取json中的全部键值对

 JSONObject json1=JSONObject.fromObject("{'username' : '11111','clientid' : '','password' : '222222'}");
Map<String, Object> map =json1;
for (Entry<String, Object> entry : map.entrySet()) {
System.out.println(entry.getKey()+"="+entry.getValue());
}

三提取json中某个数组的所有值

public class JsonExtracter { public static void main(String[] args) { String s = "{\"name\":\"a\",\"family\":[\"张三\",\"李四\"]}";

        JSONObject jsonObject = JSON.parseObject(s);

        //注意:family中的内容带有中括号[],所以要转化为JSONArray类型的对象
JSONArray family = jsonObject.getJSONArray("family"); for (int i = 0; i < family.size(); i++) { //提取出family中的所有
String s1 = (String) family.get(i);
System.out.println("currentFamily:" + s1); } }

java获取json数组格式中的值的更多相关文章

  1. 转载: java获取json数组格式中的值

    转自:https://www.cnblogs.com/kkxwze/p/11134846.html   第一种方法: String str = "{'array':[{'id':5,'nam ...

  2. java获取Json和http状态码

    最近再做接口自动化测试,其中有几个方法比较重要 1.获取http状态码 /* * 返回接口状态码 * */ public static String getHttpCode(String url) { ...

  3. Java 处理json字符串value中多余的双引号

    转: Java 处理json字符串value中多余的双引号 一.错误场景 json字符串的value值中有多余的双引号 1.直接上错误的json字符串 1 String errorJsonStr =  ...

  4. zepto区别于jquery获取select表单选中的值

    在jquery下,我们获取select表单选中的值通常是通过$('select').val()来实现,这样的方式简单又明了,或者通过$('select option[selected]').text( ...

  5. 获取Json数据某节点的值

    时间匆忙,直接上代码,回家还得做清蒸鱼呢! #region 获取Json字符串某节点的值 /// <summary> /// 获取Json字符串某节点的值 /// </summary ...

  6. EL表达式获取Map和List中的值

    EL表达式获取Map和List中的值   EL表达式取Map中的值: 当Map中是String,String时 后台servlet中: Map<String, String> map1 = ...

  7. java解析json数组

      java解析json数组 import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; ...

  8. javascript 获取iframe里页面中元素值的方法 关于contentWindow和contentDocumen

    javascript 获取iframe里页面中元素值的方法 IE方法:document.frames['myFrame'].document.getElementById('test').value; ...

  9. js 获取json数组里面数组的长度

    作为一个前端页面开发者第一次处理json数据,遇到了‘js 获取json数组里面数组的长度’?竟然不知道 json没有.length属性(真是要嘲讽下自己),少壮不努力老大徒伤悲啊!以前都是去寻求男朋 ...

随机推荐

  1. watir安装——windows环境

    默认情况下,gem sources 都是https://rubygems.org/

  2. SecureCRT For Mac安装、破解、使用详细总结

    转:https://blog.csdn.net/so_geili/article/details/83315852#_4 https://www.sednax.com/download.php

  3. Retrofitting Analysis

    Retrofitting Analysis To figure out the process of retrofitting[1] objective updating, we do the fol ...

  4. iOS 图表工具charts介绍

    charts是一个很好的绘图工具,功能非常强大,可以用来绘制折线,柱状图,饼状图,k线图,k线分时图,雷达图,气泡图等等,charts是一款仿照安卓 MPAndroidChart而来的一个基于swif ...

  5. web开发(十) struts2之图片验证码

    1.配置前端页面 <!-- 验证码--> <div class="form-group " style="padding-left: 9%;" ...

  6. python生成密码字典

    import itertools as its words = 'abcdefghijklmnopqrstuvwxyz1234567890' r = its.product(words, repeat ...

  7. javascript-->getElementsByClass

        //通过类名获取元素    //obj->目标元素的上一层元素  cName->目标类名 tagName->目标的标签类型(可缺省)    function getEleme ...

  8. 解密Go语言之 pprof

    相信很多人都听过“雷神 3”关于性能优化的故事.在一个 3D 游戏引擎的源码里,John Carmack 将 1/sqrt(x) 这个函数的执行效率优化到了极致. 一般我们使用二分法,或者牛顿迭代法计 ...

  9. 简单通讯聊天 群聊功能 Windows下的客户端 Linux下的epoll服务器

    1 服务器代码  Linux eclipse C++ //======================================================================= ...

  10. 一张图包含SEO一切要点

    看到一张好图 from http://www.rongyipiao.com/?p=8