zoukankan      html  css  js  c++  java
  • java解析json字符串

    json字符串内容为:

    {
        "xiaowang": [{
            "age": "21",
            "weight": "120"
        }],
        "xiaomei": [{
            "age": "24",
            "weight": "135"
        }],
        "xiaohong": [{
            "age": "22",
            "weight": "104"
        }]
    }

    java代码为,最后可以得到小王的年纪

    import org.springframework.boot.configurationprocessor.json.JSONArray;
    import org.springframework.boot.configurationprocessor.json.JSONObject;
    
    public class test {
        public static void main(String[] args) {
            String content = "{"xiaowang": [{"age": "21","weight": "120"}],"xiaomei": [{"age": "24","weight": "135"}],"xiaohong": [{"age": "22","weight": "104"}]}";
            try {
                JSONObject jsonObject = new JSONObject(content);
                String xiaowang = jsonObject.getString("xiaowang");
                JSONArray jsonArray = new JSONArray(xiaowang);
                JSONObject jsonObject1 = jsonArray.getJSONObject(0);
                String age = jsonObject1.getString("age");
                System.out.println(age);
            }catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
  • 相关阅读:
    mysql多表关系
    mysql支持的数据类型
    数据库基本操作
    线程基础
    生产者和消费者模型
    并发编程一
    元类
    linux 关机/重启命令
    linux前后台任务切换
    centos7最小化安装后,yum安装pstree及mlocate
  • 原文地址:https://www.cnblogs.com/fengzi7314/p/15393428.html
Copyright © 2011-2022 走看看