我尝试使用GSON对JSON字符串进行格式化,但格式化后所有值都显示为JSON。这是JSON字符串(我通过Rest API从服务器获取此字符串):
{"getInformationResult ":{
"BE_Active":false,"BE_Owner_ID":0,"BT_ID":0,"CLC_销售":0,"CLC_Shared_Balance":false,"Cash":false,"Client_Active":false,"Client_Client":null,"Client_ID":0,"Clients_Balance_By_Brand":null,"Contact_Active":false,"Contact_ID":0,"Credit":false,"Currency_ID":0,"Error_Codes":null,"Errors":[{" Error_Code":" 101"," Error_Description":" Login:Invalid User or Password"," Error_ID":27," Error_Name":" Invalid User Or Password "}]," Father_ID":0," Labels":null," Language_ID":0," Parent_ID":0," Schedule_Time_End":null," Schedule_Time_Start":null," Server_Date_Time":null," Server_TZ_ISO_Notation":null," TT_ID":0," TZ_ISO_Notation":null," Template_ID":0," User_Active":false," User_Email":null," User_Name":null}}
这就是我用来解释的:
Gson gson = new Gson(); getInformationResult getInformationResult = new getInformationResult(); getInformationResult respuesta = gson. fromJson(response,getInformationResult.class);
public class Uncategorized {
@SerializedName("Errors")
public Errors Errors;
@SerializedName("User_Name")
public String User_Name;
@SerializedName("BE_Active")
public String BE_Active;
@SerializedName("BE_Owner_ID")
public String BE_Owner_ID;
@SerializedName("BT_ID")
public String BT_ID;
@SerializedName("CLC_Sale")
public String CLC_Sale;
@SerializedName("CLC_Shared_Balance")
public String CLC_Shared_Balance;
@SerializedName("Cash")
public String Cash;
@SerializedName("Client_Active")
public String Client_Active;
@SerializedName("Client_Alias")
public String Client_Alias;
@SerializedName("Client_ID")
public String Client_ID;
@SerializedName("Clients_Balance_By_Brand")
public String Clients_Balance_By_Brand;
@SerializedName("Contact_Active")
public String Contact_Active;
@SerializedName("Contact_ID")
public String Contact_ID;
@SerializedName("Credit")
public String Credit;
@SerializedName("Currency")
public String Currency;
@SerializedName("Error_Codes")
public String Error_Codes;
@SerializedName("Father_ID")
public String Father_ID;
@SerializedName("Labels")
public String Labels;
@SerializedName("Language_ID")
public String Language_ID;
@SerializedName("Parent_ID")
public String Parent_ID;
@SerializedName("Schedule_Time_End")
public String Schedule_Time_End;
@SerializedName("Schedule_Time_Start")
public String Schedule_Time_Start;
@SerializedName("Server_Date_Time")
public String Server_Date_Time;
@SerializedName("Server_TZ_ISO_Notation")
public String Server_TZ_ISO_Notation;
@SerializedName("TZ_ISO_Notation")
public String TZ_ISO_Notation;
@SerializedName("TT_ID")
public String TT_ID;
@SerializedName("Template_ID")
public String Template_ID;
@SerializedName("User_Active")
public String User_Active;
@SerializedName("User_Email")
public String User_Email;
public getInformationResult(Errors Errors, String User_Name,String BE_Active,String BE_Owner_ID, String BT_ID,String CLC_Sale,String CLC_Shared_Balance, String Cash,
String Client_Active, String Client_Alias,String Client_ID,String Clients_Balance_By_Brand, String Server_TZ_ISO_Notation,String Contact_Active,
String Contact_ID, String Credit, String Currency,String Error_Codes,String Father_ID,String Labels,String Language_ID,String Parent_ID,
String Schedule_Time_End,String Schedule_Time_Start,String Server_Date_Time, String TZ_ISO_Notation,String TT_ID, String Template_ID, String User_Active, String User_Email ) {
this.Errors = Errors;
this.User_Name = User_Name;
this.BE_Active = BE_Active;
this.BE_Owner_ID = BE_Owner_ID;
this.BT_ID=BT_ID;
this.CLC_Sale = CLC_Sale;
this.CLC_Shared_Balance=CLC_Shared_Balance;
this.Cash=Cash;
this.Client_Active=Client_Active;
this.Client_Alias = Client_Alias;
this.Client_ID = Client_ID;
this.Clients_Balance_By_Brand = Clients_Balance_By_Brand;
this.Server_TZ_ISO_Notation = Server_TZ_ISO_Notation;
this.Contact_Active=Contact_Active;
this.Contact_ID=Contact_ID;
this.Credit=Credit;
this.Currency=Currency;
this.Error_Codes=Error_Codes;
this.Father_ID=Father_ID;
this.Labels=Labels;
this.Language_ID=Language_ID;
this.Parent_ID=Parent_ID;
this.Schedule_Time_End=Schedule_Time_End;
this.Schedule_Time_Start=Schedule_Time_Start;
this.TZ_ISO_Notation=TZ_ISO_Notation;
this.TT_ID=TT_ID;
this.Server_Date_Time=Server_Date_Time;
this.Template_ID=Template_ID;
this.User_Active=User_Active;
this.User_Email=User_Email;
}
@NonNull
@Override
public String toString() {
return new Gson().toJson(this);
}
字符串
}
2条答案
按热度按时间5lwkijsr1#
您不需要 *SerializedName**注解 *。
这些是针对 keys 不是有效的 Java 变量名的情况,例如 “abc-123” 或 “123 abc”。
这里有一个例子。
个字符
cwtwac6a2#
如果有人需要答案,我用这样的代码解决了我的问题:
public class Uncategorized {
字符串
}
public class Uncategorized {
型
}
public class Uncategorized {
型