我正在使用JSONObject在我的Android应用程序中创建一个新的json。 但我遇到一个奇怪的问题,我观察到我的json字段名称被“a”,“value”,“b”:“value_1”,“c”:value2“等字母所取代 这适用于较少数量的孩子,但随着数量的增加,它会扭曲json:
示例json:
{
"Employees" : [
{
"userId":"rirani",
"jobTitleName":"Developer",
"firstName":"Romin",
"lastName":"Irani",
"preferredFullName":"Romin Irani",
"employeeCode":"E1",
"region":"CA",
"phoneNumber":"408-1234567",
"emailAddress":"romin.k.irani@gmail.com"
},
{
"userId":"nirani",
"jobTitleName":"Developer",
"firstName":"Neil",
"lastName":"Irani",
"preferredFullName":"Neil Irani",
"employeeCode":"E2",
"region":"CA",
"phoneNumber":"408-1111111",
"emailAddress":"neilrirani@gmail.com"
},
{
"userId":"thanks",
"jobTitleName":"Program Directory",
"firstName":"Tom",
"lastName":"Hanks",
"preferredFullName":"Tom Hanks",
"employeeCode":"E3",
"region":"CA",
"phoneNumber":"408-2222222",
"emailAddress":"tomhanks@gmail.com"
}
]
}
输出损坏:
{
"Employees" : [
{
"a":"rirani",
"b":"Developer",
"c":"Romin",
"d":"Irani",
"e":"Romin Irani",
"f":"E1",
"g":"CA",
"h":"408-1234567",
"i":"romin.k.irani@gmail.com"
},
{
"a":"nirani",
"b":"Developer",
"c":"Neil",
"d":"Irani",
"e":"Neil Irani",
"f":"E2",
"g":"CA",
"h":"408-1111111",
"i":"neilrirani@gmail.com"
},
{
"a":"thanks",
"b":"Program Directory",
"c":"Tom",
"d":"Hanks",
"e":"Tom Hanks",
"f":"E3",
"g":"CA",
"h":"408-2222222",
"i":"tomhanks@gmail.com"
}
]
}
这是Android JSON对象中的错误吗?任何提示?
答案 0 :(得分:1)
此问题基于app level gradle文件中的proguard规则,该值为false,如下所示。
minifyEnabled false
另外,你可以在你的pojo类中添加键,如
@SerializedName("userId") // pass your json key
private String userId;