Trabla: Gson: java json parser example
Gson (also known as Google Gson) is an open source Java library to serialize and deserialize Java objects to (and from) JSON.
https://en.wikipedia.org/wiki/Gson
Solving:
1. Download Gson jar from "The Central Repository"
http://search.maven.org/#artifactdetails%7Ccom.google.code.gson%7Cgson%7C2.6.2%7Cjar
2. Drag-n-drop Gson .jar into your Eclipse project source folder
4. Source code
package com.codingtrabla.demos;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.Gson;
public class GsonUsageDemo {
public static void main(String[] args) {
Gson gson = new Gson();
List<String> list = new ArrayList<String>();
list.add("New York");
list.add("London");
list.add("Sydney");
String json = gson.toJson( list );
System.out.println(json);
}
}
["New York","London","Sydney"]
No comments:
Post a Comment