2017-02-15 1 views
0

JSON/GEOJSON 형식의 API (Aquaplot)에서 데이터를 가져옵니다. 이것은 데이터 저장 방법에 대한 간단한보기입니다. 모든 좌표를 검색하여 배열에 저장하려고합니다.Java GeoJSON/JSON을 조작하는 방법은 무엇입니까?

데이터를 어떻게 조작합니까?

{ "type": "FeatureCollection", "features": 
[ 
    { 
     "type": "Feature", 
     "properties": { 
     "total_length": 558.49614719928, 
     "seca_length": 0, 
     "crossed": [ 
      "suez-canal" 
     ] 
     }, 
     "geometry": { 
     "type": "LineString", 
     "coordinates": [ 
      [32.67333984375, 33.174341551002], 
      [32.3423, 31.2228], 
      [32.310393, 31.094417], 
      [32.319995, 30.811504], 
      [32.342453, 30.703486], 
      [32.305385, 30.568682], 
      [32.396751, 30.357018], 
      [32.449684, 30.285923], 
      [32.500598, 30.260175], 
      [32.52428, 30.244705], 
      [32.560229, 30.198274], 
      [32.585092, 29.973555], 
      [32.567552, 29.923606], 
      [32.714583, 29.448333], 
      [33.237083, 28.553278], 
      [34.018333, 27.504556], 
      [35.92529296875, 24.806681353852] 
     ] 
     } 
    } ] } 
+0

당신은 조작에 의해 무엇을 의미합니까? 'JSON' 데이터를 어떤 종류의 데이터 구조 (예 : 데이터를 '비 직렬화')로로드 하시겠습니까? 어떤 코드로 보여줄 수 있습니까? 귀하의 질문을 명확히하십시오. – ventiseis

+0

위의 결과는 API에서 가져온 것입니다. 그 JSON 결과입니다. 모든 데이터를 검색 할 수 있지만 일종의 계산을 수행하는 데 필요한 좌표 부분 만 필요합니다. 좀 더 정확하게, 나는 어떤 종류의 데이터 구조로 JSON 데이터를로드하고 싶다. –

답변

0
public static void main(String args[]) throws Exception 
{ 
    //String url = "http://restcountries.eu/rest/v1/name/norway"; 
    String url = "  "; 

    URL obj = new URL(url); 
    HttpURLConnection con = (HttpURLConnection) obj.openConnection(); 

    // optional default is GET 
    con.setRequestMethod("GET"); 

    //add request header 
    con.setRequestProperty("Authorization", " "); 
    con.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); 

    int responseCode = con.getResponseCode(); 
    System.out.println("\nSending 'GET' request to URL : " + url); 
    System.out.println("Response Code : " + responseCode); 
    System.out.println(con.getInputStream()); 


    BufferedReader in = new BufferedReader(
      new InputStreamReader(con.getInputStream())); 
    String inputLine; 
    StringBuffer response = new StringBuffer(); 

    while ((inputLine = in.readLine()) != null) { 
     response.append(inputLine); 

    } 
    in.close(); 

    //print result 
    System.out.println(response.toString()); 


    JSONObject jsonResponse=new JSONObject(response.toString()); 
    if(jsonResponse==null) 
    { 
    System.out.println("jsnresponse \n \n\n\n"); 
    throw new IllegalArgumentException("Books cannot be null"); 

    } 



Fill the url and key . 

response.tostring() is your response which further with the help pattern matcher you can parse and get the desired result. 
+0

고맙습니다. 이제 API 결과를 검색 할 수있게되었지만보다 정확히 내가 좌표 부품을 검색하려고했습니다. 어떻게해야합니까? 좌표는 중첩 된 배열에 있습니다. –

+0

전체 응답은 json 객체입니다. 어느 기하학을 검색하고 json 배열 좌표보다 좌표가 필요합니다. 나에게 URL과 액세스 키를 주면 내가 도울 수있어. –

관련 문제