Ich möchte auf Android-Apps über Web-Service zugreifen. Im Webservice wird die neue Registrierung durchgeführt. In den Android-Apps wird die XML-Datei für die neue Registrierung erstellt. Die Daten werden erfolgreich in der SQL Server-Datenbank gespeichert und sie wird ordnungsgemäß vom Webdienst gespeichert und gibt Daten in jason string zurück.Android, Zeichenfolge kann nicht in JSONObject konvertiert werden
Aber als String in JSONObject umgewandelt wird es mir geben, Fehler wie folgt aus:
org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
LoginActivity
package com.example.shy.wel.activity;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.android.volley.Request.Method;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.example.shy.wel.LoadingActivity;
import com.example.shy.wel.MainActivity;
import com.example.shy.wel.R;
import com.example.shy.wel.app.AppConfig;
import com.example.shy.wel.app.AppController;
import com.example.shy.wel.helper.SQLiteHandler;
import com.example.shy.wel.helper.SessionManager;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class LoginActivity extends Activity {
private static final String TAG = RegisterActivity.class.getSimpleName();
private Button btnLogin;
private Button btnLinkToRegister;
private EditText inputEmail;
private EditText inputPassword;
private ProgressDialog pDialog;
private SessionManager session;
private SQLiteHandler db;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Intent loading = new Intent(this, LoadingActivity.class);
startActivity(loading);
inputEmail = (EditText) findViewById(R.id.email);
inputPassword = (EditText) findViewById(R.id.password);
btnLogin = (Button) findViewById(R.id.btnLogin);
btnLinkToRegister = (Button) findViewById(R.id.btnLinkToRegisterScreen);
// Progress dialog
pDialog = new ProgressDialog(this);
pDialog.setCancelable(false);
// SQLite database handler
db = new SQLiteHandler(getApplicationContext());
// Session manager
session = new SessionManager(getApplicationContext());
// Check if user is already logged in or not
if (session.isLoggedIn()) {
// User is already logged in. Take him to main activity
Intent intent = new Intent(LoginActivity.this, MainActivity.class);
startActivity(intent);
finish();
}
// Login button Click Event
btnLogin.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
String email = inputEmail.getText().toString().trim();
String password = inputPassword.getText().toString().trim();
// Check for empty data in the form
if (!email.isEmpty() && !password.isEmpty()) {
// login user
checkLogin(email, password);
} else {
// Prompt user to enter credentials
Toast.makeText(getApplicationContext(),
"Please enter the credentials!", Toast.LENGTH_LONG)
.show();
}
}
});
// Link to Register Screen
btnLinkToRegister.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
Intent i = new Intent(getApplicationContext(),
RegisterActivity.class);
startActivity(i);
finish();
}
});
}
/**
* function to verify login details in mysql db
* */
private void checkLogin(final String email, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Logging in ...");
showDialog();
StringRequest strReq = new StringRequest(Method.POST,
AppConfig.URL_LOGIN, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Login Response: " + response.toString());
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) {
// user successfully logged in
// Create login session
session.setLogin(true);
// Now store the user in SQLite
String uid = jObj.getString("uid");
JSONObject user = jObj.getJSONObject("user");
String name = user.getString("name");
String email = user.getString("email");
String created_at = user.getString("created_at");
// Inserting row in users table
db.addUser(name, email, uid, created_at);
// Launch main activity
Intent intent = new Intent(LoginActivity.this,
MainActivity.class);
startActivity(intent);
finish();
} else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(),
errorMsg, Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
// JSON error
e.printStackTrace();
Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("email", email);
params.put("password", password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
private void showDialog() {
if (!pDialog.isShowing())
pDialog.show();
}
private void hideDialog() {
if (pDialog.isShowing())
pDialog.dismiss();
}
}
Mein logcat
04-22 13:41:55.092 14473-14521/com.example.shy.wel E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7facc84b6ad0
04-22 13:41:55.117 14473-14473/com.example.shy.wel W/System.err: org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
04-22 13:41:55.117 14473-14473/com.example.shy.wel W/System.err: at org.json.JSON.typeMismatch(JSON.java:111)
04-22 13:41:55.117 14473-14473/com.example.shy.wel W/System.err: at org.json.JSONObject.<init>(JSONObject.java:160)
04-22 13:41:55.118 14473-14473/com.example.shy.wel W/System.err: at org.json.JSONObject.<init>(JSONObject.java:173)
04-22 13:41:55.118 14473-14473/com.example.shy.wel W/System.err: at com.example.shy.wel.activity.LoginActivity$3.onResponse(LoginActivity.java:129)
04-22 13:41:55.118 14473-14473/com.example.shy.wel W/System.err: at com.example.shy.wel.activity.LoginActivity$3.onResponse(LoginActivity.java:120)
04-22 13:41:55.118 14473-14473/com.example.shy.wel W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:60)
04-22 13:41:55.118 14473-14473/com.example.shy.wel W/System.err: at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
04-22 13:41:55.118 14473-14473/com.example.shy.wel W/System.err: at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at android.os.Handler.handleCallback(Handler.java:739)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at android.os.Looper.loop(Looper.java:148)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5417)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at java.lang.reflect.Method.invoke(Native Method)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
04-22 13:41:55.119 14473-14473/com.example.shy.wel W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
04-22 13:41:55.123 1606-1779/system_process W/InputMethodManagerService: Window already focused, ignoring focus gain of: [email protected] attribute=null, token = [email protected]
04-22 13:41:55.174 14473-14521/com.example.shy.wel W/EGL_emulation: eglSurfaceAttrib not implemented
04-22 13:41:55.174 14473-14521/com.example.shy.wel W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0x7facbe4a2500, error=EGL_SUCCESS
04-22 13:41:58.629 14473-14521/com.example.shy.wel E/Surface: getSlotFromBufferLocked: unknown buffer: 0x7facc84b6c90
die Daten von Ihrem Web-Service zurückgegeben ist nicht gültig, versuchen Sie es hier zu überprüfen http://jsonlint.com/ – user3802077
Ihre zurückgegebene Zeichenfolge ist '
NoChinDeluxe