Let's say we have the following string:
String x = "abc";
My question is how would I use the Gson library to convert the given string, to the following JSON string:
{
x : "abc"
}
http://www.studytrails.com/java/json/java-google-json-parse-json-to-java.jsp
class Albums {
public String x;
}
Lets convert this to JSON and see how it looks
import com.google.gson.Gson;
public class JavaToJsonAndBack {
public static void main(String[] args) {
Albums albums = new Albums();
albums.x= "abc";
Gson gson = new Gson();
System.out.println(gson.toJson(albums));
}
}
This is how the resulting JSON looks like
{"x":"abc"}
String x = "abc"into a classStringClassand use Gson to convert it.