アンドロイドでユーザー入力パラメータを使用してJSONからデータを取得するにはどうすればよいですか?私は一部を呼び出し、あなたのJavaファイルにユーザー入力パラメータでアンドロイドでJSON GETメソッドを解析する方法は?
private static JSONObject get(Context ctx, String sUrl) {
HttpURLConnection connection = null;
try {
URL url = new URL(sUrl);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestProperty("Authorization",
"Basic " + encodedAuthentication);
connection.setRequestProperty("Accept-Charset", "utf-8,*");
Log.d("Get-Request", url.toString());
try {
BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(connection.getInputStream()));
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line).append("\n");
}
bufferedReader.close();
Log.d("Get-Response", stringBuilder.toString());
return new JSONObject(stringBuilder.toString());
} finally {
connection.disconnect();
}
} catch (Exception e) {
Log.e("ERROR", e.getMessage(), e);
return null;
}
}
private static String buildSanitizedRequest(String url,
Map<String, String> mapOfStrings) {
Uri.Builder uriBuilder = new Uri.Builder();
uriBuilder.encodedPath(url);
if (mapOfStrings != null) {
for (Map.Entry<String, String> entry : mapOfStrings.entrySet()) {
Log.d("buildSanitizedRequest", "key: " + entry.getKey()
+ " value: " + entry.getValue());
uriBuilder.appendQueryParameter(entry.getKey(),
entry.getValue());
}
}
String uriString;
try {
uriString = uriBuilder.build().toString(); // May throw an
// UnsupportedOperationException
} catch (Exception e) {
Log.e("Exception", "Exception" + e);
}
return uriBuilder.build().toString();
}
そして、あなたのJSONを以下のコードを貼り付け
、以下のコードは、あなたの問題の実行可能解を与えるだろうと考えてい
こんにちはSurya、http://stackoverflow.com/help/how-to-askを見て、あなたはその問題の完全な説明を投稿するべきです。 – Bethan
@ Bクマール、GETメソッドを使用してJSONを解析する方法は? – suryac
JSONを投稿することもできますか –