发送字符串数组安卓到PHP


send string array android to php

如何将字符串数组安卓发送到php?

IM 使用 Suger CRM 和 android.in Suger CRM REST.php有这个模块

 Method [  public method login ] {

      - Parameters [3] {
        Parameter #0 [  $user_auth ]
        Parameter #1 [  $application ]
        Parameter #2 [  $name_value_list ]
      }
    }

$user_auth有两个值user_auth.user_nameuser_auth.password

如何将值发送到此$user_auth参数

我的应用程序有以下内容

 String user_name = userName.getText().toString();
 String password = pass.getText().toString();

我的登录名.java

public class Login extends ActionBarActivity implements View.OnClickListener {
    EditText userName, pass;
    Button login;
    private ProgressDialog pDialog;
    JSONParser jsonParser = new JSONParser();
    private static final String LOGIN_URL = "http://crm.wakensys.com/service/v2/rest.php";
    private static final String TAG_SUCCESS = "sucess";
    private static final String TAG_MESSAGE = "message";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.login);
        userName = (EditText) findViewById(R.id.editText_userN);
        pass = (EditText) findViewById(R.id.editText_pass);
        login = (Button) findViewById(R.id.btn_login);
        login.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub
        Log.d("v", "Login button clicked");
        new AttemptLogin().execute();
    }
    class AttemptLogin extends AsyncTask<String, String, String>{
        @Override
        protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(Login.this);
        pDialog.setMessage("Attempting login..");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
        pDialog.dismiss();
        }
        @Override
        protected String doInBackground(String... args) {
             // Check for success tag
            int success;
            String user_auth[];
            String user_name = userName.getText().toString();
            String password = pass.getText().toString();
            try {
                // Building Parameters
                List<NameValuePair> params = new ArrayList<NameValuePair>();
                params.add(new BasicNameValuePair("user_auth[]", user_name));
                params.add(new BasicNameValuePair("user_auth[]", password));

                Log.d("request!", "starting..");
                // getting product details by making HTTP request
                JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST", params);
                if(json == null)
                    return null;
                // check your log for json response
                Log.d("Login attempt", json.toString());
                // json success tag
                success = json.getInt(TAG_SUCCESS);
                if (success == 1) {
                    Log.d("Login Successful!", json.toString());
                    Intent i = new Intent(Login.this, Success.class);
                    finish();
                    startActivity(i);
                    return json.getString(TAG_MESSAGE);
                }else{
                    Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                    return json.getString(TAG_MESSAGE);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
            return null;
        }
        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog once product deleted
            pDialog.dismiss();
            if (file_url != null){
                Toast.makeText(Login.this, file_url, Toast.LENGTH_LONG).show();
            }
        }
    }
}

任何帮助..

我自己不做Java,但是如果你的PHP数组看起来像

$user_auth = array("username" => "myUsernameHere", "password" => "myPasswordHere");

那么你可以使用$json_user_auth = json_encode($user_auth, JSON_FORCE_OBJECT);并将$json_user_auth发送到Java,然后解码JSON,确定吗?