아래 코드를 찾으십시오. 이걸 실행하면 org.json.simple.JSONObject cannot be cast to org.json.simple.JSONArray
예외가 발생합니다. 도와주세요.Json-Simple, 캐스트 예외
{ "tsNow": 1376325485, "데이터": { "나는
public static void main(String[] args) throws Exception {
URL website = new URL("http://MY_TESTING_SITE");
URLConnection connection = website.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
StringBuilder response = new StringBuilder();
String inputLine;
while ((inputLine = in.readLine()) != null)
response.append(inputLine);
in.close();
JSONParser parser = new JSONParser();
Object obj = parser.parse(response.toString());
JSONObject jsonObject = (JSONObject) obj;
System.out.println(jsonObject.get("data")); //Works fine till here and get proper output
JSONArray msg = (JSONArray) jsonObject.get("data");
Iterator<String> iterator = msg.iterator();
while (iterator.hasNext()) {
System.out.println(iterator.next());
}
}
샘플 JSON 출력은 아래 그림처럼 보이는 JSON 안에 모든 값을 인쇄하기 위해 노력하고있어 1352 ": { "for_loyal ":"1 ", "offer_image ":"http://MY_IMAGE.jpg " "상태 ":"1 ", "brand_id ":"22 ", "ID ":"1352 " "brand_image": "http://MY_BRAND_IMAGE.png", "제목": "미국에 승리 20 가족 휴가", "설명": "일부 설명", "EXPIRY_DATE": 1383018300, "BRAND_NAME": "브랜드 이름", "store_locations"[ { " CITY_ID ":"46 ", "country_id ":"9 " } ] } }, "성공 "사실 }
추출 할 JSON을 넣을 수 있습니까? –
"data"속성의 내용은 무엇입니까? – Bohemian