Google이나 스택 오버플로에서 발견 된 많은 게시물과 자습서를 연구했으며 아무도 실제로 이미지를 업로드하는 데 JSONParser
을 사용하지 않았습니다. 내가 찾은 모든 코드는 Android 대신 웹 사이트에서 그렇게 사용되었습니다.JSONParser를 사용하여 이미지를 업로드하는 기능을 수행하는 방법은 무엇입니까?
JSONParser
을 사용하여 이미지를 업로드하려면 어떻게해야합니까?
갤러리에서 업로드하거나 카메라로 사진을 찍고 내 앱에서 직접 업로드 할 수 있기를 원했습니다.
public class JSONParser {
static InputStream is = null;
static JSONObject jObj = null;
static String result = "";
static String json = "";
// constructor
public JSONParser() {
}
public JSONObject makeHttpRequest(String url, String method,
List<NameValuePair> params) {
// Making HTTP request
try {
// check for request method
if(method == "POST") {
// request method is POST
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
} else if(method == "GET") {
// request method is GET
DefaultHttpClient httpClient = new DefaultHttpClient();
String paramString = URLEncodedUtils.format(params, "utf-8");
url += "?" + paramString;
HttpGet httpGet = new HttpGet(url);
HttpResponse httpResponse = httpClient.execute(httpGet);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
json = sb.toString();
} catch (Exception e) {
Log.e("Buffer Error", "Error converting result " + e.toString());
}
// try parse the string to a JSON object
try {
jObj = new JSONObject(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
}
// return JSON String
return jObj;
}
}
우리는 매개 변수를 전달하여 그것을 할 수 있지만 아무도 그것을 사용하지 않는 것 같다 :
JSONParser
클래스는 다음과 같습니다. 구현이 불가능하거나 버그가 있습니까?