Retrofit and Jackson and parsing JSON

前端 未结 2 1624
攒了一身酷
攒了一身酷 2021-02-02 13:48

I am using Retrofit with Jackson. For some reasons I cannot parse the following JSON:

[
    {
        \"ProfileImage\": null,
        \"UserName\": \"joe\"
    }         


        
相关标签:
2条回答
  • 2021-02-02 14:39

    Use Square's converter by adding this to your build.gradle:

    compile 'com.squareup.retrofit:converter-jackson:1.9.0'
    

    Afterwards you can activate it by adding .setConverter(new JacksonConverter()) to your RestAdapter builder.

    0 讨论(0)
  • 2021-02-02 14:40

    with new versions of OkHTTP it seems its done with:

    Retrofit retrofit = new Retrofit.Builder()
                    .baseUrl(API_URL)
                    .addConverterFactory(JacksonConverterFactory.create())
                    .build();
    
    0 讨论(0)
提交回复
热议问题