繁体   English   中英

在java中读取JSON对象的多个参数

[英]Reading multiple parameters of JSON objects in java

大家好,我在阅读这个文件时遇到了问题,谁能建议我如何使用模型名称和标语以及这个模型的变体代码来阅读这个文件。 我是使用 java 读取 json 的新手,每当我尝试读取获取此异常时,即线程“main”中的异常 java.lang.ClassCastException: class org.json.simple.JSONObject cannot be cast to class org.json.simple .JSONArray(org.json.simple.JSONObject 和 org.json.simple.JSONArray 位于加载程序“app”的未命名模块中)对此有任何参考吗?

    {
      "models": {
        "IN": [
          {
            "modelName": "Inter",
            "modelTagline": "A classic  roadster",
            "models": [
              {
                "ID": "Inter-0",
                "engineCapacity": "Test",
                "imageUrl": "INT.png",
                "mailCCBTR": "",
                "mailToBTR": "",
                "mailerBikeImageBTR": "orange.jpg",
                "modelCodeBTR": "XYZ23",
                "name": "Int 0",
                "power": "47 Bhp",
                "showCatalogue": true,
                "showInDealer": false,
                "showInREPrime": true,
                "tagLine": "A classic roadster",
                "torque": "52 Nm",
                "variants": [
                  {
                    "highlights": [
                      "LOREM IPSUM",
                      "",
                      "",
                      ""
                    ],
                    "id": "int 50",
                    "imageUrl": "3F_GTred_000.png",
                    "name": "red",
                    "showBookNow": false,
                    "showConfigureNow": true,
                    "showInDealer": false,
                    "showInREPrime": true,
                    "tankColor": "Red",
                    "tankImage": "Red_01.png",
                    "variantCode": "AVC",
                    "webp": "000.webp",
                    "webp-mobile-1x": "3.webp",
                    "webp-mobile-2x": "2.webp"
                  },
                  {
                    "highlights": [
                      "LOREM IPSUM",
                      "",
                      "",
                      ""
                    ],
                    "id": "int 50",
                    "imageUrl": "V000.png",
                    "name": "Blue",
                    "showBookNow": false,
                    "showConfigureNow": true,
                    "showInDealer": false,
                    "showInREPrime": true,
                    "tankColor": "Blue",
                    "tankImage": "Blue_01.png",
                    "variantCode": "SADSAD32",
                    "webp": "F.webp",
                    "webp-mobile-1x": "LOREM IPSUM.webp",
                    "webp-mobile-2x": "LOREM IPSUM.webp"
                  },
                  {
                    "highlights": [
                      "LOREM IPSUM",
                      "",
                      "",
                      ""
                    ],
                    "id": "int 50",
                    "imageUrl": "80.png",
                    "name": "Crush",
                    "showBookNow": false,
                    "showConfigureNow": true,
                    "showInDealer": false,
                    "showInREPrime": true,
                    "tankColor": "Crush",
                    "tankImage": "h_01.png",
                    "variantCode": "56565SDGFS",
                    "webp": "h_000.webp",
                    "webp-mobile-1x": "LOREM IPSUM.webp",
                    "webp-mobile-2x": "LOREM IPSUM.webp"
                  },
                  {
                    "highlights": [
                      "It's a blast to ride on twisty back roads, highways or the urban jungle, with equal ease and grace, for novices and experienced riders alike",
                      "",
                      "",
                      ""
                    ],
                    "id": "inter50",
                    "imageUrl": "00.png",
                    "name": "Downtown Drag",
                    "showBookNow": false,
                    "showConfigureNow": true,
                    "showInDealer": false,
                    "showInREPrime": true,
                    "tankColor": "Downtown Drag",
                    "tankImage": "01.png",
                    "variantCode": "lkasdsd",
                    "webp": "int 500.webp",
                    "webp-mobile-1x": "int 500.webp",
                    "webp-mobile-2x": "test.webp"
                  },
                  {
                    "highlights": [
                      "It's a blast to ride on twisty back roads, highways or the urban jungle, with equal ease and grace, for novices and experienced riders alike",
                      "",
                      "",
                      ""
                    ],
                    "id": "int 50",
                    "imageUrl": "k_000.png",
                    "name": "Sunset Strip",
                    "showBookNow": false,
                    "showConfigureNow": true,
                    "showInDealer": false,
                    "showInREPrime": true,
                    "tankColor": "Sunset Strip",
                    "tankImage": "Black_01.png",
                    "variantCode": "AFDF23",
                    "webp": "TEST.webp",
                    "webp-mobile-1x": "TEST3.webp",
                    "webp-mobile-2x": "T.webp"
                  }      
            ]
          
    }

大家好,我在阅读这个文件时遇到了问题,谁能建议我如何使用模型名称和标语以及这个模型的变体代码来阅读这个文件。 我是使用 java 读取 json 的新手,每当我尝试读取获取此异常时,即线程“main”中的异常 java.lang.ClassCastException: class org.json.simple.JSONObject cannot be cast to class org.json.simple .JSONArray(org.json.simple.JSONObject 和 org.json.simple.JSONArray 位于加载程序“app”的未命名模块中)

看起来这个 json 没有完成。 如果我有误解,您可以上传 .json 文件。 如果这个json是全部,请在json末尾附加“]}]}}”。 祝你好运。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM