【发布时间】:2015-11-18 09:36:32
【问题描述】:
我在我的应用中使用 Retrofit 2.0 和 GSON 转换器。
在我的 JSON 中,我有 6 个字段,3 个用于 int 和 String,其中 3 个由 RegExps 组成(1 个 int 用于“id”,模型类中有 5 个 String 字段)。
String 和 int fiends 解析得非常好,但在带有 RegExp GSON 的字段上返回 NULL。
这是 JSON 的示例:
[
{
"id": "22",
"iso": "TTR",
"name": "Lolo",
"check": "^77",
"full": "^77[0-9]{9}$",
"default": "+77"
},
{
"id": "23",
"iso": "RTT",
"name": "Polo",
"check": "^7",
"full": "^7[0-6,8,9][0-9]{9}$",
"default": "+7"
}
]
片段中的代码:
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(URL_API)
.client(SSLSuppressClient.trustcert())
.addConverterFactory(GsonConverterFactory.create())
.build();
GetPhones getPhonesInfo = retrofit.create(GetPhones.class);
Call<ArrayList<GetPhones> call = getPhonesInfo.getPhones();
call.enqueue(new Callback<ArrayList<GetPhones>>() {
@Override
public void onResponse(Response<ArrayList<GetPhones>> response, Retrofit retrofit) {
Toast.makeText(getActivity(), "Success!", Toast.LENGTH_SHORT).show();
}
@Override
public void onFailure(Throwable t) {
Toast.makeText(getActivity(), "Failure!", Toast.LENGTH_SHORT).show();
Log.d("LOG", t.getMessage());
}
});
和模型类:
public class GetPhones {
int id;
String iso;
String name;
String lop_check;
String lop_full;
String lop_default;
}
怎么了?
【问题讨论】:
-
从字符类中删除
,.^7[0-6,8,9][0-9]{9}$==>^7[0-689][0-9]{9}$ -
@Tushar 不幸的是这不是我的 JSON,所以我不能
标签: android regex gson retrofit