그래서 당신은 당신이 전화에서 얻을 jsonStr를 사용
public String makeServiceCall(String reqUrl) {
String response = null;
try {
URL url = new URL(reqUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
InputStream in = new BufferedInputStream(conn.getInputStream());
response = convertStreamToString(in);
} catch (MalformedURLException e) {
Log.e(TAG, "MalformedURLException: " + e.getMessage());
} catch (ProtocolException e) {
Log.e(TAG, "ProtocolException: " + e.getMessage());
} catch (IOException e) {
Log.e(TAG, "IOException: " + e.getMessage());
} catch (Exception e) {
Log.e(TAG, "Exception: " + e.getMessage());
}
return response;
}
다음 JSON의 STR을 URL을 전달하고 점점하여 jsonString는이 같은 서비스 전화를 걸 수 있습니다 얻기 위해 서버를 호출해야 이렇게.
String jsonStr = makeServiceCall(String reqUrl);
JSONArray jsonArr= new JSONArray(jsonStr);
JSONObject jsonObjectOne = jsonArr.getJSONObject(0);
String param1 = jsonObjectOne.getString("param1");
JSONObject jsonObjectTwo = jsonArr.getJSONObject(1);
String param2 = jsonObjectTwo.getString("param2");
@Dalton 나는 구문 분석하는 방법을 알고하지 않았다. 당신이 작성한 링크는 "JSON 문자열을 코드별로 얻었습니다."라고 묻는 질문을했습니다. – jancooth