これはJSONObjectを要求するコードです。 String要求を処理している間、完全に動作しましたが、JSONObjectが必要です。出力API出力をチェックするにはボレーを使用してJSONObjectRequestのJSONobjectを受信できません
Map<String, String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
params.put("request", "login");
JSONObject jsonObj = new JSONObject(params);
String url="http://example.com/android/login.php";
JsonObjectRequest postRequest = new JsonObjectRequest(Request.Method.POST, url,jsonObj,
new Response.Listener<JSONObject>()
{
@Override
public void onResponse(JSONObject response) {
// response
// JSONObject json = JSONObject.toJson(response);
// Toast.makeText(Login.this, "Your ID is ."+response, Toast.LENGTH_LONG).show();
//Log.d("Response", response.toString());
Intent r = new Intent(Login.this,Cus_home.class);
startActivity(r);
}
},
new Response.ErrorListener()
{
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.d("Error.Response", error.toString());
}
}
);
mRequestQueue.add(postRequest);
です: [{"id":"77","type":"1"}]
しかし、Androidのコードを実行した後、私はこの
Error.Response: com.android.volley.ParseError: org.json.JSONException: End of input at character 1 of
を取得する任意のヘルプのヘルプは本当にあなたは
次のようになりますが、あなたが見たことがあり、{ "firstNameの": "ジョン"、 "lastNameの" "ドウ"} http://stackoverflow.com/questions/23220695/send-post-request with json-data-using-volley?この構文は次のように使用することをお勧めします: 'final JSONObject jsonBody = new JSONObject(" {\ "type \":\ "example \"} ");' –
JsonObjectの受信に問題があります。それが私を助けることができるかどうかわからない –
@SimonPhoenix JsonObjectは私の入力フィールドからです。もっと何かを提案してください –