0

我有三个 EditText

  1. 用户名
  2. 姓名
  3. 电子邮件

我想在用户登录后自动填充这些 EditText,并且我希望使用json. 任何人都可以帮助我做到这一点。我是json解析的新手所以请帮忙

4

1 回答 1

1

您必须在单击时实现该方法才能获取 EditText 的值。

String username = youedittext.getText().toString();
String name = youedittext2.getText().toString();
String email = youedittext3.getText().toString();

DefaultHttpClient client = new DefaultHttpClient();
                    ArrayList<NameValuepair> nvp = new ArrayList<NameValuePair>();
                    nvp.add(new BasicNameValuePair("username", username));
                    nvp.add(new BasicNameValuePair("name", name));
                    nvp.add(new BasicNameValuePair("mail", mail));
        HttpPost hpost = new HttpPost(url);
        hpost.setEntity(new UrlEncodedFormEntity());
        HttpResponse response = client.execute(hpost);

        HttpEntity entity = response.getEntity();
        InputStream is = entity.getContent();

        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();
        String result = sb.toString();

        JSONObject jobject = new JSONObject(result);
                    //Here you have to read the JSONObject it's very easy

                Log.i("Content:",jobject.toString());
于 2012-07-09T11:15:56.557 回答