Java数据结构之JSON解析

本文介绍了JSON的基本概念,作为轻量级数据交换格式,它被广泛用于网络数据传输。接着,文章详细讲解了JSON的两种基本数据结构——对象和数组,并通过示例展示了Java中使用FastJson库进行JSON解析的方法,包括引入依赖和常用API的使用。此外,还提及了JsonPath,一种用于从JSON文档中提取数据的表达式,文章提供了JsonPath的依赖引入和使用示例。
摘要由CSDN通过智能技术生成

JSON简介


  • JSON是一种轻量级的数据交换格式,采用完全独立于编程语言的文本格式来存储和表示数据。本质上就是一个"特殊格式"的字符串。
  • JSON 是网络上用来传输数据使用最广泛的数据格式没有之一,且JSON比XML更轻量级

 

JSON的数据结构


  • {对象}:保存对象(JSONObject)
  • [数组]: 保存数组(JSONArray)
  • 提示 : JSON描述对象的语法格式很像字典,但是不是字典,仅仅是键值对的形式很像。

json示例:

{
    "code":200,
    "data":{
        "cars":[
            {
                "maxCapOfLuggage":5,
                "capOfLuggage":2,
                "capOfPerson":4,
                "carDesc":"经济5座",
                "carIntroduction":"",
                "carPictures":[
                    "http://basedata.bj.bcebos.com/cartype/100005.png"
                ],
                "carType":1,
                "carTypeId":100005,
                "currency":"RMB",
                "currencyRate":1,
                "priceId":"bd1434bb-f0c3-4b2b-b30a-785149b58f4a",
                "price":199,
                "priceLabel":"199.00",
                "basePrice":199,
                "priceSign":"a32c5cee4652db098d190c1646eadc94",
                "models":"服务车型:xB或同级别车型",
                "priceDeadTime":"2019-07-03 15:53:16",
                "quoteList":[
                    "Quote1",
                    "Quote2",
                    "Quote3"
                ],
                "seatType":5,
                "serviceTags":[
                    "中文司导"
                ],
                "urgentFlag":0,
                "expenseDetail":null
            },
            {
                "maxCapOfLuggage":8,
                "capOfLuggage":3,
                "capOfPerson":6,
                "carDesc":"经济7座",
                "carIntroduction":"",
                "carPictures":[
                    "http://basedata.bj.bcebos.com/cartype/100007.png"
                ],
                "carType":1,
                "carTypeId":100007,
                "currency":"RMB",
                "currencyRate":1,
                "priceId":"1bafa544-6af9-4c42-af60-4a976e2575f1",
                "price":246,
                "priceLabel":"246.00",
                "basePrice":246,
                "priceSign":"675f81a66d2f0199cb55962e79daa405",
                "models":"服务车型:格锐Maxcruz或同级别车型",
                "priceDeadTime":"2019-07-03 15:53:16",
                "quoteList":[
                    "Quote1",
                    "Quote2",
                    "Quote3"
                ],
                "seatType":7,
                "serviceTags":[
                    "中文司导"
                ],
                "urgentFlag":0,
                "expenseDetail":null
            },
            {
                "maxCapOfLuggage":5,
                "capOfLuggage":2,
                "capOfPerson":4,
                "carDesc":"舒适5座",
                "carIntroduction":"",
                "carPictures":[
                    "http://basedata.bj.bcebos.com/cartype/200005.png"
                ],
                "carType":2,
                "carTypeId":200005,
                "currency":"RMB",
                "currencyRate":1,
                "priceId":"17eefa46-e3fe-45d3-be74-3948b4627f6e",
                "price":230,
                "priceLabel":"230.00",
                "basePrice":230,
                "priceSign":"28be1fedbc722b5e3ae598e2334748ce",
                "models":"服务车型:LS400或同级别车型",
                "priceDeadTime":"2019-07-03 15:53:16",
                "quoteList":[
                    "Quote1",
                    "Quote2",
                    "Quote3"
                ],
                "seatType":5,
                "serviceTags":[
                    "中文司导"
                ],
                "urgentFlag":0,
                "expenseDetail":null
            },
            {
                "maxCapOfLuggage":8,
                "capOfLuggage":3,
                "capOfPerson":6,
                "carDesc":"舒适7座",
                "carIntroduction":"",
                "carPictures":[
                    "http://basedata.bj.bcebos.com/cartype/200007.png"
                ],
                "carType":2,
                "carTypeId":200007,
                "currency":"RMB",
                "currencyRate":1,
                "priceId":"903994cb-f3b0-4acc-978e-ed85786af622",
                "price":261,
                "priceLabel":"261.00",
                "basePrice":261,
                "priceSign":"57443a58f36c6633a8d809de0096652f",
                "models":"服务车型:Express或同级别车型",
                "priceDeadTime":"2019-07-03 15:53:16",
                "quoteList":[
                    "Quote1",
                    "Quote2",
                    "Quote3"
                ],
                "seatType":7,
                "serviceTags":[
                    "中文司导"
                ],
                "urgentFlag":0,
                "expenseDetail":null
            },
            {
                "maxCapOfLuggage":12,
                "capOfLuggage":5,
                "capOfPerson":8,
                "carDesc":"舒适9座",
                "carIntroduction":"",
                "carPictures":[
                    "http://basedata.bj.bcebos.com/cartype/200009.png"
                ],
                "carType":2,
                "carTypeId":200009,
                "currency":"RMB",
                "currencyRate":1,
                "priceId":"4a86aefd-4cbf-4088-afb2-ac5a605011d0",
                "price":431,
                "priceLabel":"431.00",
                "basePrice":431,
                "priceSign":"b1c60f5e19378dfa067d77ba8783230a",
                "models":"服务车型:海狮(Hiace)或同级别车型",
                "priceDeadTime":"2019-07-03 15:53:16",
                "quoteList":[
                    "Quote1",
                    "Quote2",
                    "Quote3"
                ],
                "seatType":9,
                "serviceTags":[
                    "中文司导"
                ],
                "urgentFlag":0,
                "expenseDetail":null
            },
            {
                "maxCapOf
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值