0

I have json data like this :

 {\"FinalResult\":\"[{\\\"id\\\":11,\\\"organizationNameGE\\\":\\\"erer\\\",\\\"organizationNameEN\\\":\\\"rerer\\\",\\\"cardNumber\\\":\\\"3434343\\\",\\\"startDate\\\":\\\"02/04/2018\\\",\\\"period\\\":1,\\\"endDate\\\":\\\"02/06/2018\\\",\\\"priority\\\":\\\"middle
 important\\\",\\\"$$hashKey\\\":\\\"0QI\\\"}]\"}

and i want to get json array items and use it in my code , here is my java code:

 JSONParser parser = new JSONParser(); 
 JSONObject jsonObjectR= null;

 try {
     //jsonObjectR = (JSONObject) parser.parse("{\"FinalResult\":\"[{\\\"id\\\":11,\\\"organizationNameGE\\\":\\\"erer\\\",\\\"organizationNameEN\\\":\\\"rerer\\\",\\\"cardNumber\\\":\\\"3434343\\\",\\\"startDate\\\":\\\"02/04/2018\\\",\\\"period\\\":1,\\\"endDate\\\":\\\"02/06/2018\\\",\\\"priority\\\":\\\"middle important\\\",\\\"$$hashKey\\\":\\\"0QI\\\"}]\"}");
     jsonObjectR=(JSONObject) parser.parse(new String(msg));
 } catch (ParseException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
 }

 JSONArray jsonArray = (JSONArray) jsonObjectR.get("FinalResult");
 JSONArray json1 = jsonArray;
Sustem.out.println(json1 [0].priority)

it throws exception like this:

 org.json.simple.JSONObject cannot be cast to org.json.JSONObject

i have replaced org.json.simple.JSONObject this import by org.json.JSONObject but this hasn't change anything, what should i add to make this task properly?

Vikrant Kashyap
  • 6,398
  • 3
  • 32
  • 52
Sagitarius
  • 353
  • 1
  • 4
  • 20

0 Answers0