【发布时间】:2019-12-26 05:31:41
【问题描述】:
在登录时出现此错误,如果您知道任何解决方案,请不要降级,请指导我。我还检查了不同的堆栈溢出帖子,但他们都在谈论通过改造来修剪字符串或其他解决方案,但我无法解决它。我使用截击。
我的 Json 文件:-
{
"error": false,
"user": [
{
"user_id": "123",
"customer_name": "Abc",
"email": "abc@example.com",
"salt": "123abc",
"phone": "1234567890",
"address": "Enter Address",
"postal_code": "1234"
}
]
}
这是我的 Java 类:-
@Override
protected String doInBackground(Boolean... booleen) {
ExampleApi exampleApi = new ExampleApi();
LoginUser result;
try {
result = exampleApi.loginPost(sharedPreferences.getString("abc_id", ""), semail, fcmToken, spassword);
Gson gson = new Gson();
String json = gson.toJson(result);
JSONObject jObj = new JSONObject(json);
Log.e("result1", String.valueOf(jObj));
if (jObj.getString("error").equalsIgnoreCase("false")) {
JSONArray jsonArray = jObj.getJSONArray("user");
JSONObject jsonObject1 = jsonArray.getJSONObject(0);
return "true";
}else {
String errormsg = jObj.getString("error_msg");
return errormsg;
}
} catch (ApiException e) {
e.printStackTrace();
Log.e("error", e.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
【问题讨论】:
-
你可以编辑问题并发布
LoginUser类。 -
需要调查
loginPost和LoginUser。你能添加这些吗? -
我也使用这种方式,但它也不起作用:- Gson gson = new Gson();字符串结果1 = String.valueOf(result); JsonReader reader = new JsonReader(new StringReader(result1)); reader.setLenient(true); String json = gson.fromJson(reader, UserInfo.class); JSONObject jObj = new JSONObject(json);
-
能贴出错误日志吗?
-
E/error: com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: 使用 JsonReader.setLenient(true) 在第 2 行第 2 列路径 $ @Sajith 接受格式错误的 JSON
标签: android api android-volley malformed