Reputation: 11
Hi guys I am getting issue while reading this file can anyone suggest me how to read this file by using model name and tagline and also variant code of this model. I am new to reading in json using java , whenever I am trying to read getting this exception i.e. Exception in thread "main" java.lang.ClassCastException: class org.json.simple.JSONObject cannot be cast to class org.json.simple.JSONArray (org.json.simple.JSONObject and org.json.simple.JSONArray are in unnamed module of loader 'app') Any reference for this?
{
"models": {
"IN": [
{
"modelName": "Inter",
"modelTagline": "roadster",
"models": [
{
"ID": "test-650",
"engineCapacity": "Twin",
"imageUrl": "https://www.test.png",
"mailCCBTR": "",
"mailToBTR": "",
"mailerBikeImageBTR": "orange.jpg",
"modelCodeBTR": "test",
"name": "Interc50",
"power": "5rpm",
"showCatalogue": true,
"showInDealer": false,
"showInREPrime": true,
"tagLine": "A classic British roadster",
"torque": "5rpm",
"variants": [
{
"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": "test-650",
"imageUrl":"https://www.test.png",
"name": "Canyon Red",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Canyon Red",
"tankImage": "https://www.test.png",
"variantCode": "ty",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
},
{
"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": "test-650",
"imageUrl":"https://www.test.png",,
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Ven",
"tankImage": "https://www.test.png",
"variantCode": "VS",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
},
{
"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": "test-650",
"imageUrl":"https://www.test.png",,
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Granite ",
"tankImage": "https://www.test.png",
"variantCode": "VT",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
},
{
"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": "test-650",
"imageUrl":"https://www.test.png",,
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Grey ",
"tankImage": "https://www.test.png",
"variantCode": "60PE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
},
{
"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": "test-650",
"imageUrl":"https://www.test.png",,
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Orange ",
"tankImage": "https://www.test.png",
"variantCode": "VPE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
},
{
"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": "test-650",
"imageUrl":"https://www.test.png",,
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Blue",
"tankImage": "https://www.test.png",
"variantCode": "SVSE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
},
{
"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": "test-650",
"imageUrl":"https://www.test.png",,
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "rgra ",
"tankImage": "https://www.test.png",
"variantCode": "LE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png",
}
],
"webp": "https://www.royalenfield.com/node/assets/configurator-master-images/Web/webp/Models/1280x853---INT.webp",
"webp-mobile-1x": "https://www.royalenfield.com/node/assets/configurator-master-images/Web/webp-mobile-1x/Models/1280x853---INT.webp",
"webp-mobile-2x": "https://www.royalenfield.com/node/assets/configurator-master-images/Web/webp-mobile-2x/Models/1280x853---INT.webp"
}
]
}
]
}
]
}
}
Upvotes: 0
Views: 33
Reputation: 69
Your JSON is invalid, I fixed it using https://jsonchecker.com/ and https://jsonprettier.com/
{
"models": {
"IN": [
{
"modelName": "Inter",
"modelTagline": "roadster",
"models": [
{
"ID": "test-650",
"engineCapacity": "Twin",
"imageUrl": "https://www.test.png",
"mailCCBTR": "",
"mailToBTR": "",
"mailerBikeImageBTR": "orange.jpg",
"modelCodeBTR": "test",
"name": "Interc50",
"power": "5rpm",
"showCatalogue": true,
"showInDealer": false,
"showInREPrime": true,
"tagLine": "A classic British roadster",
"torque": "5rpm",
"variants": [
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Canyon Red",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Canyon Red",
"tankImage": "https://www.test.png",
"variantCode": "ty",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
},
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Ven",
"tankImage": "https://www.test.png",
"variantCode": "VS",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
},
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Granite ",
"tankImage": "https://www.test.png",
"variantCode": "VT",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
},
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Grey ",
"tankImage": "https://www.test.png",
"variantCode": "60PE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
},
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Orange ",
"tankImage": "https://www.test.png",
"variantCode": "VPE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
},
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "Blue",
"tankImage": "https://www.test.png",
"variantCode": "SVSE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
},
{
"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": "test-650",
"imageUrl": "https://www.test.png",
"name": "Blue",
"showBookNow": false,
"showConfigureNow": true,
"showInDealer": false,
"showInREPrime": true,
"tankColor": "rgra ",
"tankImage": "https://www.test.png",
"variantCode": "LE",
"webp": "https://www.test.png",
"webp-mobile-1x": "https://www.test.png",
"webp-mobile-2x": "https://www.test.png"
}
],
"webp": "https://www.royalenfield.com/node/assets/configurator-master-images/Web/webp/Models/1280x853---INT.webp",
"webp-mobile-1x": "https://www.royalenfield.com/node/assets/configurator-master-images/Web/webp-mobile-1x/Models/1280x853---INT.webp",
"webp-mobile-2x": "https://www.royalenfield.com/node/assets/configurator-master-images/Web/webp-mobile-2x/Models/1280x853---INT.webp"
}
]
}
]
}
}
Upvotes: 2