프로그래밍언어
[Java] JSON형식 Parsing
skokieh
2020. 6. 9. 20:40
728x90
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
|
package http;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import org.json.JSONArray;
import org.json.JSONObject;
public class Http9 {
public static void main(String[] args) throws UnsupportedEncodingException {
NetworkUtil nu = new NetworkUtil();
String url = "http://ggoreb.com/python/json/data3.jsp";
String param = "source=ko&target=fr&text="; //한국어, 프랑스어
param += URLEncoder.encode("안녕하세요. 저는 자바 개발자입니다.", "utf-8");
String clientId = "OpcnSsAIn37qIu6Iyad6";
String clientSecret = "p7qtbsYx8N";
String result = nu.get(url); //11번라인 네트워크유틸에서
System.out.println(result);
JSONArray json = new JSONArray(result);
for (int i = 0; i < json.length(); i++) {
JSONObject obj = json.getJSONObject(i);
JSONArray address = obj.getJSONArray("address"); //address배열. 배열의 키로address
String add = address.getString(0);
System.out.println(add);
}
}
}
|
cs |
