마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

json 파싱 url을 추가해서 두 개의 json 파싱을 하려면 어떻게 해야 하는가요?ㅠ

–2 추천

안녕하세요^^

아래와 같이 json 파싱을 하였습니다~

json 파싱 url을 추가해서 두 개의 json 파싱을 하려면 어떻게 해야 하는가요?ㅠ

추가할 url과 파싱내용, 기존의 url과 파싱내용입니다~

감사합니다~

http://www.appang.kr/nas/api/join.json.asp?os=a&ap=392f39a9837d7e0491da58443e5ebc0f&a=4b08a73cd2524c79c65e2cfa7497868f&ua=2d14e86c-ee9b-4917-9a27-06a4676ab635&ud=ecloud1234&ajip=192.168.0.1

{"result":0,"url":"market:\/\/details?id=aio.co.kr"}

http://www.ecloud.kr/cpa/jsontest/json_test7.asp

{"items":[{"keyno":2,"keyvalue":"4b08a73cd2524c79c65e2cfa7497868f","packagename":"aio.co.kr"}]}

public static void onT(View v) {

URL url = null;
try {
url = new URL("http://www.ecloud.kr/cpa/jsontest/json_test7.asp");
} catch (MalformedURLException e) {
e.printStackTrace();
}
try {
@SuppressWarnings("unused")
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
}

String line = null;
static String page = "";
static EditText et_webpage_src;
EditText etKeyno;
EditText etKeyvalue;
EditText etPackagename;

@SuppressLint("HandlerLeak")
void processing_Data() {
Properties prop = new Properties();
prop.setProperty("keyno", etKeyno.getText().toString());
prop.setProperty("keyvalue", etKeyvalue.getText().toString());
prop.setProperty("packagename", etPackagename.getText().toString());
String encodedString = encodeString(prop);
URL url = null;
HttpURLConnection urlConnection = null;
BufferedInputStream buf = null;
try {
Log.e("", "processing_Data1"+ line);
// URL 접속
url = new URL("http://www.ecloud.kr/cpa/jsontest/json_test7.asp");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);

urlConnection.setUseCaches(false);

urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
DataOutputStream out = null;
Log.e("", "processing_Data2"+ line);
out = new DataOutputStream(urlConnection.getOutputStream());
out.writeBytes(encodedString);
out.flush();

buf = new BufferedInputStream(urlConnection.getInputStream());

BufferedReader bufreader = new BufferedReader(new InputStreamReader(buf, "utf-8"));

while ((line = bufreader.readLine()) != null) {
page += line;
Log.e("", ""+ line);
}
if(!page.isEmpty()) {
buiHandler.sendEmptyMessage(0);
}
} catch (Exception e){

Log.e("", "processing_Data1"+ e.getMessage());

} finally {

urlConnection.disconnect();
}
Log.e("", ""+ page);
}
@SuppressLint("HandlerLeak")
public static Handler buiHandler = new Handler() {
@SuppressLint("HandlerLeak")
public void handleMessage(Message msg) {

try {
JSONObject json = new JSONObject(page);

JSONArray jArr = json.getJSONArray("items");

for (int i=0; i<jArr.length(); i++) {

json = jArr.getJSONObject(i);
int keyno = Integer.parseInt(json.getString("keyno"));
String str = String.valueOf(keyno);
String keyvalue = json.getString("keyvalue");
String packagename = json.getString("packagename");

Log.d("JS1", str);
Log.d("JS2", keyvalue);
Log.d("JS3", packagename);

et_webpage_src.append(keyno + "\n");
et_webpage_src.append(keyvalue + "\n");
et_webpage_src.append(packagename + "\n");

}
} catch (Exception e){
}
}
};

marimari (520 포인트) 님이 2015년 9월 23일 질문

1개의 답변

0 추천
각각 url을 호출해서 파싱하면 됩니다.

하나를 먼저하고, 거기서 나온 url을 이용하는게 아닌 이상 두 url은 관련이 없어보이니 필요할 때 호출하게 만드세요.
쎄미 (162,410 포인트) 님이 2015년 9월 23일 답변
...