ブラウザに表示されるように適切な順序でjsonオブジェクトの応答を取得する必要がありますが、ランダムです。これは、クライアントからの応答を取得するための私の Post 関数です。また、すべての配列フィールドを文字列ではなくイテレータで取得したい
jsonserch2.getString("@id");
塗りつぶしイテレーターにイテレーター myVeryOwnIterator=jsonserch2.keys() を使用します
String response = postData("http://url",generateRequestJson(this));
public static String postData(String url, String json) {
final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost(url);
httppost.setHeader("Content-type", "application/x-www-form-urlencoded");
final ArrayList<NameValuePair> values = new ArrayList<NameValuePair>();
values.add(new BasicNameValuePair("data", json));
String response = "";
try {
httppost.setEntity(new UrlEncodedFormEntity(values));
final HttpResponse httpResponse = httpclient.execute(httppost);
response = convertInputStreamToString(httpResponse);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response;
}
private static String convertInputStreamToString(HttpResponse response) {
BufferedReader bufferedReader = null;
try {
bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
// JsonReader reader = new JsonReader(new
// InputStreamReader(response.getEntity().getContent()));
// Log.e("",""+reader);
final StringBuffer stringBuffer = new StringBuffer("");
String line = "";
final String LineSeparator = System.getProperty("line.separator");
//
//
while ((line = bufferedReader.readLine()) != null) {
stringBuffer.append(line + LineSeparator);
}
return stringBuffer.toString();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return "";
}