0
我是android開發新手。我需要解析這個代碼到php數據庫。我可以從logcat獲得響應。我只需要解析這個網站數據庫masterlist。有人可以幫助我與這些請。非常感謝。在Android中解析JSON響應
public class MainActivity extends Activity implements OnClickListener {
private EditText inputCompanyID;
private EditText inputBranchID;
private EditText inputFName;
private EditText inputLName;
private EditText inputGenderID;
private EditText inputBirthdate;
private EditText inputEmail;
private EditText inputMobile;
private EditText inputItemID;
private EditText inputVoucherID;
private Button btnCreateProduct;
private ProgressDialog pDialog;
JSONParser jsonParser = new JSONParser();
// JSON Node names
private static final String TAG_SUCCESS = "success";
private static final String TAG_MESSAGE = "message";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// new MyAsyncTask().execute();
inputCompanyID = (EditText) findViewById(R.id.inputCompanyID);
inputBranchID = (EditText) findViewById(R.id.inputBranchID);
inputLName = (EditText) findViewById(R.id.inputLName);
inputFName = (EditText) findViewById(R.id.inputFName);
inputGenderID = (EditText) findViewById(R.id.inputGenderID);
inputBirthdate = (EditText) findViewById(R.id.inputBirthdate);
inputEmail = (EditText) findViewById(R.id.inputEmail);
inputMobile = (EditText) findViewById(R.id.inputMobile);
inputItemID = (EditText) findViewById(R.id.inputItemID);
inputVoucherID = (EditText) findViewById(R.id.inputVoucherID);
btnCreateProduct = (Button) findViewById(R.id.btnAddCustomer);
btnCreateProduct.setOnClickListener(this);
}
// button click event
@Override
public void onClick(View v) {
// creating new product in background thread
new PostComment().execute();
}
public void sendCustomer() {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("oAuth", "test123"));
params.add(new BasicNameValuePair("action", "add-customer"));
params.add(new BasicNameValuePair("company_id", inputCompanyID.getText().toString()));
params.add(new BasicNameValuePair("branch_id", inputBranchID.getText().toString()));
params.add(new BasicNameValuePair("lastname", inputLName.getText().toString()));
params.add(new BasicNameValuePair("firstname", inputFName.getText().toString()));
params.add(new BasicNameValuePair("gender_id", inputGenderID.getText().toString()));
params.add(new BasicNameValuePair("birth_date", inputBirthdate.getText().toString()));
params.add(new BasicNameValuePair("email", inputEmail.getText().toString()));
params.add(new BasicNameValuePair("mobile", inputMobile.getText().toString()));
params.add(new BasicNameValuePair("item_id", inputItemID.getText().toString()));
params.add(new BasicNameValuePair("voucher_id", inputVoucherID.getText().toString()));
String response = ISparkLib.getHttpResponse("http://192.168.0.110/teezly/API/1.0/customer.php", params);
Log.e("PARAMS",""+response);
return;
}
class PostComment extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(MainActivity.this);
pDialog.setMessage("Creating Product..");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try
{
sendCustomer();
Thread.sleep(0);
}catch(Exception e){
}
}
}).start();
return null;
}
}}
解析什麼?你能解釋一下你的問題嗎? – 2014-02-13 10:52:15
檢查:http://stackoverflow.com/questions/21480634/unable-to-loop-through-dynamic-json-string-recursively-in-android/21480997#21480997 – user2450263
你想解析迴應?它是一個JSON字符串?如果你想在你的網站數據庫中添加一些值,你必須在服務器上開發一個可以接收值的APi – Dyna