qq_37961932
择忆霖心
采纳率96.7%
2017-03-25 12:23

厉害的人看一下,我这个代码对不对

已采纳

post请求,然后解析服务器返回的json请求
那里不对,大神指点一下。谢谢

 public void onClick(View view) {
                String username = usernameEdit.getText().toString();
                String password = passwordEdit.getText().toString();
                OkHttpClient client = new OkHttpClient();
                RequestBody requestBody = new FormBody.Builder()
                        .add("username", username)
                        .add("password", password)
                        .build();
                Request request = new Request.Builder()
                        .url("http://test.ourwechat.com/test/auth.php")
                        .post(requestBody)
                        .build();
                JSONObject jsonObject = null;
                try {
                    jsonObject = new JSONObject();
                   String code = jsonObject.getString("code");
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                if (code == -1){
                    Toast.makeText(Login.this,"登录失败",Toast.LENGTH_SHORT).show();
                }
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

1条回答

相关推荐