Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓-改型1.9-发布数据返回LoginActivity的无效JSON_Android_Json_Post_Gson - Fatal编程技术网

Android 安卓-改型1.9-发布数据返回LoginActivity的无效JSON

Android 安卓-改型1.9-发布数据返回LoginActivity的无效JSON,android,json,post,gson,Android,Json,Post,Gson,我在向服务器发送登录信息时出错。我尝试了很多方法来访问“isSuccessful:true”这个东西,但我失败了 改装错误消息: *D/Retrofit:* {"IsSuccessfull":false,"IncidentId":"de3d","Messages": [{"Key":"ExceptionResponse","Value":"SOME_ERRORS_OCCURED_DURING_EXECUTION"},>{"Key":"Exception","Value":"Servic

我在向服务器发送登录信息时出错。我尝试了很多方法来访问“isSuccessful:true”这个东西,但我失败了


改装错误消息:

*D/Retrofit:*

{"IsSuccessfull":false,"IncidentId":"de3d","Messages":
[{"Key":"ExceptionResponse","Value":"SOME_ERRORS_OCCURED_DURING_EXECUTION"},>{"Key":"Exception","Value":"ServiceExecutor.InvalidApplication"}]}*

*D/Retrofit: 
<--- END HTTP (224-byte body)*
并应返回以下内容:

    {
      "Data": {something},
      "IsSuccessfull": true
    }

private void services with headerTask(){
showProgress();
JSONObject jsonMain=新的JSONObject();
JSONObject jsonParams=新的JSONObject();
试一试{
jsonParams.put(“用户名”、“fatih.kaya”);
jsonParams.put(“密码”,“11111”);
jsonParams.put(“AuthProvider”、“1”);
//jsonMain.put(“函数”、“登录”);
put(“参数”,jsonParams);
}捕获(例外e){
}
/**将示例json转换为改装typedString**/
TypedString parm=新的TypedString(jsonMain.toString());
//服务电话
serviceWithHeader.postJsonString(parm,new Callback(){
@凌驾
public void成功(对象、响应){
字符串responseString=new Gson().toJson(对象);
showSnackBar(responseString);
hideProgress();
}
@凌驾
公共无效故障(改型错误改型错误){
错误。printStackTrace();
showSnackBar(“错误:+Error.getMessage());
hideProgress();
}
});
}
***REST接口***
公共接口RestInterface{
@POST(“/auth/signin”)
void postJsonString(@Body TypedString,回调cb);
}
***服务生成器***
公共类服务生成器{
公共静态最终字符串BASE_URL=”http://xxx.xxx.xxx.xxx:xxx/api/json/";
公共静态类SessionRequestInterceptor实现RequestInterceptor{
@凌驾
公共无效截获(请求门面请求){
addHeader(“内容类型”、“应用程序/json”);
addHeader(“x-Application-Key”、“PIRLWjnl”);
}
}
公共静态S createServiceWithJsonHeader(类serviceClass){
RestAdapter.Builder=new RestAdapter.Builder()
.setEndpoint(基本URL)
.setRequestInterceptor(新的SessionRequestInterceptor());
RestAdapter adapter=builder.build();
adapter.setLogLevel(RestAdapter.LogLevel.FULL);
返回adapter.create(serviceClass);
}

使用Gson和jsonschema2pojo.org比手动解析Json要方便得多

改型(2.0之前)附带(我认为是Gson)作为默认Json解析器,因此您唯一应该更改的是:

serviceWithHeader.postJsonString(parm, new Callback<LoginResponse>() { //This is the key ingredient
/* implementation */
}
创建这些类并在回调类型中进行设置后,改型应注意填充这些字段。 如果您不想从json响应创建此类类,我创建了一个小脚本,您可能会发现它很有用

我更改了这个部分

TypedString parm = new TypedString(jsonMain.toString());
为此:

TypedString parm = new TypedString(jsonParams.toString());
因此,
参数
单词不需要添加


感谢尝试帮助的人=)

当我使用post man并使用标题和正文时,您服务器的json响应是这样的吗???@SripadRaj:我已经从该网站获得了POJO,但我将在创建有效连接后使用POJO。我将用您编写的连接替换该行,(顺便说一句,我有我以前创建的LoginModel类,我认为手动解析JSON以建立连接比使用pojo类更容易)并将callbackType设置为LoginModel,它给了我相同的错误响应。我的LoginModel:public class LoginModel{(at Sign)SerializedName(“Data”)(at Sign)公开私有数据;@SerializedName(“IsSuccessfull”)@Expose private Boolean issccessfull;public Data getData(){return Data;}public void setData(Data){this.Data=Data;}public Boolean getissccessfull(){return issccessfull;}public void setissccessfull(Boolean issccessfull){this.issusccessfull=issusccessfull;}}感谢您的脚本,我将尝试它=)第二次阅读后,我看到您正在生成以下内容。{“参数”:{/*这是您实际想要发送的json*/}也许您应该尝试为请求主体创建一个类,并将其作为:void postJsonString发送(@Body LoginRequest request,Callback cb);只是澄清一下:class LoginRequest{String UserName;…more fields}
class LoginResponse {
    Object Data;
    Boolean IsSuccessfull;
}
TypedString parm = new TypedString(jsonMain.toString());
TypedString parm = new TypedString(jsonParams.toString());