As this question has been closed before actual answer for this specific problem has been found, it is here.
In java, I am using the simplejson library to handle json.
My json have this structure (truncated):
{
"assembling-tags": {
"list": [
"G_StaticCushion_R",
"G_CommutationPosition_R",
"G_PlastificationPlasticisingDuration_R",
"G_PlastificationScrewPositionAfter_R",
"G_CommutationPressure_R",
"G_DynamicCommutationDuration_R",
"G_DynamicLockingToolDuration_R",
"G_CycleTime_R",
"CYCLE_TIME",
"G_ClosureSecurityClosingToolDuration_R"
]
},
I read the json data with the following code:
try (FileReader reader = new FileReader(
"/home/hduser/eclipse-workspace/db-simulatiob/src/generator-config.json")) {
JSONObject obj = (JSONObject) jsonParser.parse(reader);
And I am trying to convert the list json array into a string array, with the following:
String[] aTag = (String[]) ((JSONObject) obj.get("assembling-tags")).get("list");
But this throws the following exception:
Exception in thread "main" java.lang.ClassCastException: org.json.simple.JSONArray cannot be cast to [Ljava.lang.String;
How can I convert the json array into a string array (String[]
) ?