Gson library in Android Studio

后端 未结 6 556
轮回少年
轮回少年 2020-12-02 21:48

Can someone give me step by step guide to add the Gson library to an Android project?

I tried the JSON built-in library but that seems to be a bit tedi

相关标签:
6条回答
  • 2020-12-02 22:11

    Read Google-gson

    Gson is a Java library that can be used to convert Java Objects into their JSON representation. It can also be used to convert a JSON string to an equivalent Java object.

    Add the following line to your MODULE LEVEL build.gradle configuration:

    dependencies {
         implementation 'com.google.code.gson:gson:2.8.5' // Old 2.8.2
    }
    
    0 讨论(0)
  • 2020-12-02 22:14

    Add following dependency or download Gson jar file

    implementation 'com.google.code.gson:gson:2.8.6'
    

    Follow github repo for documentation and more.

    0 讨论(0)
  • 2020-12-02 22:14

    Use gradle dependencies to get the Gson in your project. Your application build.gradle should look like this-

    dependencies {
      implementation 'com.google.code.gson:gson:2.8.2'
    }
    
    0 讨论(0)
  • 2020-12-02 22:17

    Gradle:

    dependencies {
       implementation 'com.google.code.gson:gson:2.8.5'
    }
    

    Maven:

    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.8.5</version> 
    </dependency>
    

    Gson jar downloads are available from Maven Central.

    0 讨论(0)
  • 2020-12-02 22:21

    There is no need of adding JAR to your project by yourself, just add dependency in build.gradle (Module lavel). ALSO always try to use the upgraded version, as of now is

    dependencies {
      implementation 'com.google.code.gson:gson:2.8.5'
    }
    

    As every incremental version has some bugs fixes or up-gradations as mentioned here

    0 讨论(0)
  • 2020-12-02 22:22

    If you are going to use it with Retrofit library, I suggest you to use Square's gson library as:

    implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
    
    0 讨论(0)
提交回复
热议问题