如何将字符串数组android发送到php?
我正在使用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_name
和user_auth.password
如何向此$user_auth
参数
我的申请已关注
String user_name = userName.getText().toString();
String password = pass.getText().toString();
我的login.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();
}
}
}
}
任何帮助..
答案 0 :(得分:0)
我自己不做Java,但如果您的PHP数组看起来像
$user_auth = array("username" => "myUsernameHere", "password" => "myPasswordHere");
然后您可以使用$json_user_auth = json_encode($user_auth, JSON_FORCE_OBJECT);
并将$json_user_auth
发送到Java然后解码JSON,当然?