2017-10-15 74 views
0

Response from Webservice using retrofit2, how to parse this data to a model call and returns the data in proper way 解析数组列表包含,整数和字符串

JobsInterface jobsInterface= ApiClient.createService(JobsInterface.class,context); 
    /*Call<String> stringCall=jobsInterface.getJobsData("data1,"data2",usernames,passwords,data5);*/ 
    Call<ArrayList<Integer>> stringCall=jobsInterface.getJobsData(url); 
    stringCall.enqueue(new Callback<ArrayList<Integer>>() { 
     @Override 
     public void onResponse(Call<ArrayList<Integer>> call, Response<ArrayList<Integer>> response) { 
      mProgress.dismiss(); 
      String data= response.errorBody().toString(); 
      String dss=response.message().toString(); 
      String dssd=response.raw().toString(); 
     } 

     @Override 
     public void onFailure(Call<ArrayList<Integer>> call, Throwable t) { 
      mProgress.dismiss(); 
     } 
    }); 
} 
    @GET 
Call<ArrayList<Integer>> getJobsData(@Url String url); 
    public class ApiClient { 


private static Retrofit retrofit; 

private static Context contextt; 
private static boolean loginFalg = false; 

private static String URL; 

private static HttpLoggingInterceptor interceptor 
     = new HttpLoggingInterceptor() 
     .setLevel(HttpLoggingInterceptor.Level.BODY); // for logging and debugging 

private static CookieHandler cookieHandler = new CookieManager(); 
private static OkHttpClient.Builder httpClientBuilder 
     = new OkHttpClient.Builder() 
     .cookieJar(new JavaNetCookieJar(cookieHandler)) 
     .connectTimeout(30, TimeUnit.SECONDS) 
     .readTimeout(60,TimeUnit.SECONDS) 
     .addInterceptor(interceptor); 

private static Gson gson = new GsonBuilder() 
     .setLenient() 
     .create(); 
private static Retrofit.Builder builder = 
     new Retrofit.Builder() 
       .baseUrl("http://localhost/") 
       .addConverterFactory(GsonConverterFactory.create(gson)); 

public static <S> S createService(Class<S> serviceClass, Context context) { 
    /*OkHttpClient okHttpClient=getUnsafeOkHttpClient();*/ 


    contextt = context; 
    retrofit = builder 
      .client(httpClientBuilder.build()) 
      .build(); 
    return retrofit.create(serviceClass); 

} 
} 

how to parse these data to a model call, so that I can apply to Call> 我收到错误java.lang.IllegalStateException的ArrayList中:预计BEGIN_ARRAY但STRING在第7行第2列路径$

我JSON格式是

   [ 
[ 

    { 
     "0": "Utilities on", 
     "1": "Utilities on", 
     "dd": "Utilities on", 
     "freqitem": "Utilities on" 
    }, 
    { 
     "0": "Vacant", 
     "1": "Vacant", 
     "dd": "Vacant", 
     "freqitem": "Vacant" 
    } 
], 
[ 

    { 
     "0": "62", 
     "1": "9a-INDIVIDUAL SUBPOE", 
     "mannerid": "62", 
     "manner": "9a-INDIVIDUAL SUBPOE" 
    }, 
    { 
     "0": "67", 
     "1": "9a-NON SERVICE SUBPO", 
     "mannerid": "67", 
     "manner": "9a-NON SERVICE SUBPO" 
    } 
], 
null, 
[ 

    { 
     "0": "19", 
     "1": "GRANDMOTHER", 
     "sid": "19", 
     "stitle": "GRANDMOTHER" 
    }, 
    { 
     "0": "5", 
     "1": "HUSBAND", 
     "sid": "5", 
     "stitle": "HUSBAND" 
    } 
], 
[ 
    "Female", 
    "Male", 
    "N/A", 
    "Unknown" 

], 
[ 
    "1", 
    "1", 
    "1", 
    "1", 
    "2", 
    "2" 

], 
[ 
    { 
     "0": "7", 
     "1": "test", 
     "2": "anm", 
     "3": "test plaintiff b & asdf" 

    }, 
    { 
     "0": "61", 
     "1": "test", 
     "2": "anm", 
     "3": "TEST PLAINTIFF1" 

    } 
], 
[ 
    { 
     "0": "7", 
     "1": "1", 
     "2": "addr", 
     "3": "addr1", 
     "4": "some add", 
     "5": "NY", 
     "6": "12313", 
     "7": "", 
     "8": "" 

    }, 
    { 
     "0": "15", 
     "1": "1", 
     "2": "1245 TEST AVENUE", 
     "3": "", 
     "4": "Saint Albans", 
     "5": "NY", 
     "6": "11412", 
     "7": "", 
     "8": "" 

    } 
] 
] 
+1

可能重复的[如何解析JSON](https://stackoverflow.com/questions/2591098/how-to-parse-json) – KeLiuyue

+0

我编辑了我的问题并添加了我的json数据。 – Myself

回答

0

[[(字典)]]

或者

阵列(阵列(字典))

阵内阵阵列 - againe字典里面-... 你应该以这样的方式写登录。

+0

这是正确的做法,但我的第二个列表包含一个字符串“null”,所以我得到解析错误,无论如何感谢回复。我刚刚使用凌空处理。 – Myself

相关问题