using gson
已回答
Hi
I'm trying to use gson in a project but haven't tried adding/using libraries before beyond the very basics. I followed these instructions https://www.jetbrains.com/idea/help/configuring-module-dependencies-and-libraries.html#d1552849e127 and added the .jar files to the Library and its showing up under Dependencies. But when I try to use it with this code
Gson gson = new Gson();
MyType myobject = gson.fromJson(jsonSource, MyType.class)
IntelliJ isn't recognising it. Do I still need to use an import statement and if so, what exactly?
Edit: Intellij just prompted me to import the appropriate file, which is(import com.google.gson.Gson) if it helps anyone here.
thanks
Rebecca
请先登录再写评论。
Intellij finally prompted me to include an import statement with the appropriate file
For anyone in the future still looking for an answer to this question, to add a dependency to an Intellij project, such as Google's Gson, go to File -> Project Structure -> Modules. Making sure you've selected the module you're working on, on the far right you should see a '+'. Since Gson has a Maven repository, go to Library -> From Maven... and then search for the dependency into the search bar. It might take a minute for it to find results, but then it will give you a list of all the different versions of Gson. Click OK to add the dependency, and then you should be good to go! If you have the dependency downloaded as a zip or a jar, select "JARs or directories" after clicking the plus and select the file on your computer.
@... thanks a lot.