zoukankan      html  css  js  c++  java
  • java获取json数组格式中的值

    第一种方法:

     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"));

    第二种方法:

     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());  
     }  

    原帖:https://www.cnblogs.com/kkxwze/p/11134846.html

  • 相关阅读:
    求逆元算法
    Almost Sorted Array
    最长不递减子序列
    (LIS)最长上升序列(DP+二分优化)
    rabbitmq延迟消息
    oracle 视图
    oracle 存储过程
    http 会话(session)详解
    系统测试
    Fiddler 手机抓包
  • 原文地址:https://www.cnblogs.com/sjzxs/p/11984058.html
Copyright © 2011-2022 走看看