-3
GSONを使用してサーバーの応答を解析しています。しかし、com.google.gson.JsonSyntaxExceptioncom.google.gson.JsonSyntaxException(GSONを使用)
は現在、私は、ハードコードJSONを送信しています。すべてのBoolean、Float値などを削除しました。現在、String値のみを解析しています。なっ
LoginPOJO.java
package com.chsoneresidential.chsone.pojo;
import com.google.gson.annotations.SerializedName;
/**
* Created by pawan on 24/10/16.
*/
public class LoginPOJO {
//High priority variables goes below.....
@SerializedName("version")
private String version;
@SerializedName("app")
private String app;
// @SerializedName("error")
// private String error;
@SerializedName("status")
private String status;
@SerializedName("message")
private String message;
@SerializedName("access_token")
private String access_token;
@SerializedName("token_type")
private String token_type;
// @SerializedName("expires")
// private String expires;
// @SerializedName("expires_in")
// private String expires_in;
@SerializedName("refresh_token")
private String refresh_token;
@SerializedName("user_id")
private String user_id;
@SerializedName("role")
private String role;
@SerializedName("user_name")
private String user_name;
@SerializedName("soc_id")
private String soc_id;
@SerializedName("user_first_name")
private String user_first_name;
@SerializedName("user_last_name")
private String user_last_name;
@SerializedName("user_email_id")
private String user_email_id;
@SerializedName("user_mobile_number")
private String user_mobile_number;
@SerializedName("user_dob")
private String user_dob;
@SerializedName("user_profile_photo")
private String user_profile_photo;
}//LoginPOJO closes here....
私は応答を取得していますMy活動:IA MはJSON SYNTAX例外を取得
@Override
public void networkResponseSuccess(String response) {
Log.d(TAG, "networkResponseSuccess: "+response);
try{
Gson gson = new Gson();
// LoginPOJO loginPOJO = gson.fromJson(reader, Staff.class);
LoginPOJO loginPOJO = gson.fromJson("{\n" +
"\t\"app\": {\n" +
"\t\t\"version\": \"v1.0\",\n" +
"\t\t\"app\": \"CHSONE\"\n" +
"\t},\n" +
"\t\"status\": \"OK\",\n" +
"\t\"message\": \"Welcome\",\n" +
"\t\"data\": {\n" +
"\t\t\"access_info\": {\n" +
"\t\t\t\"access_token\": \"OWcbj51uCe2SLQt7ad3XjUKRUawWMoUSvjSLPMVJ\",\n" +
"\t\t\t\"token_type\": \"Bearer\",\n" +
"\t\t\t\"refresh_token\": \"Bto2r5LkGdHNsYydUzi1Zj02aUl3J1CazZJ2g3F0\"\n" +
"\t\t},\n" +
"\t\t\"user_data\": {\n" +
"\t\t\t\"user_id\": \"803\",\n" +
"\t\t\t\"role\": \"admin,member\",\n" +
"\t\t\t\"user_name\": \"virajk123456\",\n" +
"\t\t\t\"soc_id\": \"846\",\n" +
"\t\t\t\"user_first_name\": \"Viraj\",\n" +
"\t\t\t\"user_last_name\": \"kaulkar\",\n" +
"\t\t\t\"user_email_id\": \"[email protected]\",\n" +
"\t\t\t\"user_mobile_number\": \"8828162613\",\n" +
"\t\t\t\"user_dob\": \"1987-09-10\",\n" +
"\t\t\t\"user_profile_photo\": \"dev.chsone.in.s3.amazonaws.com\\/846\\/avatar\\/803\\/avtar_803.jpg\"\n" +
"\t\t}\n" +
"\t}\n" +
"}", LoginPOJO.class);
System.out.println(loginPOJO);
}//try closes here....
catch(Exception e){
e.printStackTrace();
Log.e(TAG, "networkResponseSuccess: Exception = "+e);
}//catch closes here.....
LOGCAT:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 2 column 10 path $.app com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)
at com.google.gson.Gson.fromJson(Gson.java:887)
at com.google.gson.Gson.fromJson(Gson.java:852)
at com.google.gson.Gson.fromJson(Gson.java:801)
at com.google.gson.Gson.fromJson(Gson.java:773)
at com.chsoneresidential.chsone.LoginActivity.networkResponseSuccess(LoginActivity.java:166)
at com.chsoneresidential.chsone.network.NetworkResponseHandler.onResponse(NetworkResponseHandler.java:139)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:67)
at com.android.volley.toolbox.StringRequest.deliverResponse(StringRequest.java:30)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:99)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5086)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Expected a string but was BEGIN_OBJECT at line 2 column 10 path $.app
at com.google.gson.stream.JsonReader.nextString(JsonReader.java:825)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:418)
at com.google.gson.internal.bind.TypeAdapters$16.read(TypeAdapters.java:406)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:129)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:220)
... 18 more
いくつかのJSONの基本を学ぶください...それはそれは、あまりにもFX「アプリを」オブジェクトを入れ子になったとしていない「access_tokenは」...「フラットオブジェクト」ではありません同じオブジェクト... – Selvin
*私はJSOn *を知っています...いいえ、あなたはしません... "app"は文字列ではありません... "最初のレベル"では4つのプロパティしか持っていません... – Selvin
LoginPOJOオブジェクトが正しくありません。 [このウェブサイト](http://www.jsonschema2pojo.org/)を使用してモデルクラスを生成してみてください。 – MohanadMohie