A simple Java toolkit for JSON 
Tags: json

프로젝트 생성후 메이븐 설정,  디펜던시 등록

1
2
3
4
5
<dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1.1</version>
</dependency>
cs

파싱을 위한 json-simple 등록,,,




Apache HttpComponents Client

1
2
3
4
5
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.1</version>
</dependency>
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import java.io.IOException;
import java.net.URI;
import java.util.Date;
 
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
 
public class Test {
    public static void main(String[] args) throws Exception {
        String key = "키값";
        String targetDt ="20160625";
        
        HttpClient client = new DefaultHttpClient();
        URI uri = new URIBuilder("http://www.kobis.or.kr/kobisopenapi/webservice/rest/boxoffice/searchDailyBoxOfficeList.json")
                .addParameter("key", key)        //일별 박스오피스 API 서비스//영화진흥위원회
                .addParameter("targetDt", targetDt)
                .build();
        HttpGet httpGet = new HttpGet(uri);
        HttpResponse resp = client.execute(httpGet);
        String result = EntityUtils.toString(resp.getEntity(), "UTF-8");
//        System.out.println(result);
        
        JSONParser parser = new JSONParser();
        JSONObject jsonObject = (JSONObject) parser.parse(result);
        JSONObject jsonObject2 = (JSONObject) jsonObject.get("boxOfficeResult");
        JSONArray jsonArray = (JSONArray) jsonObject2.get("dailyBoxOfficeList");
        
        System.out.println("영화순위 "+targetDt);
        System.out.println();
        for(int n=0; n<11; n++){
            JSONObject jsonObject3 = (JSONObject) jsonArray.get(n);
            System.out.println(n+1);
            System.out.println(jsonObject3.get("movieNm"));
        }
    }
}
 
cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
영화순위 20160625
 
1
인디펜던스 데이 : 리써전스
2
정글북
3
특별수사: 사형수의 편지
4
컨저링 2
5
아가씨
6
비밀은 없다
7
미 비포 유
8
크리미널
9
워크래프트: 전쟁의 서막
10
곡성

결과값!r


' IOT 기반 응용 SW과정 > Web Programing' 카테고리의 다른 글

Day72 스프링 게시판  (0) 2016.06.30
Day70 페이징 처리  (0) 2016.06.28
Day68 네이버 API - 책검색  (0) 2016.06.24
Day67 네이버 API  (0) 2016.06.23
Day66 Spring-student // 스프링 인터셉터  (0) 2016.06.22

+ Recent posts