Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

android - Getting simple JSON object response using Retrofit library

I have a web query with JSON response as:

{
    "status":true,
    "result":
      {
        "id":"1",
        "name":"ABC 1",
        "email":"[email protected]",
        "password":"123456",
        "status":false,
        "created":"0000-00-00 00:00:00"
      },
    "message":"Login successfully"
}

I am using the following code for:

@GET("/stockers/login")
public void login(
        @Query("email") String email,
        @Query("password") String password,
        Callback<JSONObject> callback);

In Debugger the query made by the Retrofit library is correct, however I get an empty JSON in response.

ApiManager.getInstance().mUrlManager.login(
        email.getText().toString().trim(),
        password.getText().toString().trim(),
        new Callback<JSONObject>()
        {
            @Override
            public void success(JSONObject jsonObj, Response response)
            {
                mDialog.dismiss();
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Simply use JsonElement insted of JSONobject. Like:

@GET("/stockers/login")
Call<JsonElement> getLogin(
    @Query("email") String email,
    @Query("password") String password
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...