Android 改装:获取错误**第1行第1列输入结束**
我不知道我的问题在哪里。我必须像这样发布原始身体Android 改装:获取错误**第1行第1列输入结束**,android,post,retrofit,retrofit2,Android,Post,Retrofit,Retrofit2,我不知道我的问题在哪里。我必须像这样发布原始身体 {"app_id":"abced","app_key":"abced","request":"login","username":"abce@gmail.com","password":"1234"} 我正在使用翻新2.0。我创建了一个像 @FormUrlEncoded @POST("index.php/") Call<LoginResponse> getHome(@Field("app_id") String reques
{"app_id":"abced","app_key":"abced","request":"login","username":"abce@gmail.com","password":"1234"}
我正在使用翻新2.0。我创建了一个像
@FormUrlEncoded
@POST("index.php/")
Call<LoginResponse> getHome(@Field("app_id") String request,
@Field("app_key") String request1,
@Field("request") String request2,
@Field("username") String request3,
@Field("password") String request4);
}
依赖关系
compile 'com.squareup.retrofit2:retrofit-converters:2.0.0-beta3'
compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta3'
compile 'com.squareup.retrofit2:retrofit:2.0.0-beta3'
提前感谢将示例正文
Json
粘贴到此站点,选择sourceJson
,annotationNone
:
@FormUrlEncoded
@POST("index.php")
Call<LoginResponse> getHome1(@Field("login") String data);
然后在Api中:
@POST("index.php")
public Call<LoginResponse> getHome(@Body YourBodyPojo pojo);
身体级别:
package com.example;
public class YourBodyClass{
private String appId;
private String appKey;
private String request;
private String username;
private String password;
/**
*
* @return
* The appId
*/
public String getAppId() {
return appId;
}
/**
*
* @param appId
* The app_id
*/
public void setAppId(String appId) {
this.appId = appId;
}
/**
*
* @return
* The appKey
*/
public String getAppKey() {
return appKey;
}
/**
*
* @param appKey
* The app_key
*/
public void setAppKey(String appKey) {
this.appKey = appKey;
}
/**
*
* @return
* The request
*/
public String getRequest() {
return request;
}
/**
*
* @param request
* The request
*/
public void setRequest(String request) {
this.request = request;
}
/**
*
* @return
* The username
*/
public String getUsername() {
return username;
}
/**
*
* @param username
* The username
*/
public void setUsername(String username) {
this.username = username;
}
/**
*
* @return
* The password
*/
public String getPassword() {
return password;
}
/**
*
* @param password
* The password
*/
public void setPassword(String password) {
this.password = password;
}
}
而不是使用
@POST("index.php")
请尝试使用
@POST("/index.php")
并以
Call<LoginResponse> getHome(@Body YourBodyPojo pojo);
调用getHome(@Body YourBodyPojo pojo);
这肯定会对你有所帮助。只需重新发布一个对我有用的答案
@Override
public void onResponse(Call<Void> call, retrofit2.Response<Void> response) {
if (response.isSuccessful()) {
//Do something if response is ok
} else {
JsonParser parser = new JsonParser();
JsonElement mJson = null;
try {
mJson = parser.parse(response.errorBody().string());
Gson gson = new Gson();
MyError errorResponse = gson.fromJson(mJson, MyError.class);
} catch (IOException ex) {
ex.printStackTrace();
}
}
@覆盖
公共void onResponse(呼叫,改装2.响应){
if(response.issusccessful()){
//如果反应正常,就做些什么
}否则{
JsonParser=新的JsonParser();
JsonElement mJson=null;
试一试{
mJson=parser.parse(response.errorBody().string());
Gson Gson=新的Gson();
myErrorResponse=gson.fromJson(mJson,MyError.class);
}捕获(IOEX异常){
例如printStackTrace();
}
}
谢谢你的回复。我这样做了,但我遇到了错误**无法为类LoginRequest(我的pojo类)**创建@Body转换器。我删除了第一行@FormUrlEncoded bcoz我遇到了错误@Body参数不能与表单或多部分编码一起使用。你能告诉我如何传递登录(json)吗数据?请检查,我在上面发布了我的LoginResponse类,我的LoginRequest类与您告诉pojo类的相同,带有注释nonce Call getHome1(@Body LoginRequest pojo);是的,我正在使用GsonConvertorFactory和change annotation,但相同的错误是**无法为类LoginRequest创建@Body converter…并且我发送了诸如LoginRequest LoginRequest=new LoginRequest();LoginRequest.setUserName(“abc”);LoginRequest.setPassword(“123”)之类的数据;我已经通过查看我的工作代码更新了我的答案。你可以在我的答案中添加标题等或删除内容类型标题。你可以试试吗。我会再次告诉你,你可以发布登录过程的示例json响应吗?你的示例登录json响应是什么。如果你也更新了,我会解决你的问题。请检查我已经更新了我的登录ponse pojo类{“错误”:“帐户未激活。请检查您的电子邮件以激活您的帐户。”,“vlink”:true}这是我的json回复如果有人需要帮助,请尽管问anytime@AMANSINGH你能分享你的答案吗?我有同样的问题,但没有找到任何解决办法!@AMANSINGH我也有同样的问题,但还没有找到解决办法。你能更具体地说明你是如何解决这个问题的吗?从下面接受的答案中,我可以我找不到任何对我有效的解决办法。你能分享一下你的错误,这样对别人会有帮助吗
package com.example;
public class YourBodyClass{
private String appId;
private String appKey;
private String request;
private String username;
private String password;
/**
*
* @return
* The appId
*/
public String getAppId() {
return appId;
}
/**
*
* @param appId
* The app_id
*/
public void setAppId(String appId) {
this.appId = appId;
}
/**
*
* @return
* The appKey
*/
public String getAppKey() {
return appKey;
}
/**
*
* @param appKey
* The app_key
*/
public void setAppKey(String appKey) {
this.appKey = appKey;
}
/**
*
* @return
* The request
*/
public String getRequest() {
return request;
}
/**
*
* @param request
* The request
*/
public void setRequest(String request) {
this.request = request;
}
/**
*
* @return
* The username
*/
public String getUsername() {
return username;
}
/**
*
* @param username
* The username
*/
public void setUsername(String username) {
this.username = username;
}
/**
*
* @return
* The password
*/
public String getPassword() {
return password;
}
/**
*
* @param password
* The password
*/
public void setPassword(String password) {
this.password = password;
}
}
@POST("index.php")
@POST("/index.php")
Call<LoginResponse> getHome(@Body YourBodyPojo pojo);
@Override
public void onResponse(Call<Void> call, retrofit2.Response<Void> response) {
if (response.isSuccessful()) {
//Do something if response is ok
} else {
JsonParser parser = new JsonParser();
JsonElement mJson = null;
try {
mJson = parser.parse(response.errorBody().string());
Gson gson = new Gson();
MyError errorResponse = gson.fromJson(mJson, MyError.class);
} catch (IOException ex) {
ex.printStackTrace();
}
}