Json -> java object
-
Hi There is no problem to convert JSON which looks like this:
"{\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\"}}
to the following object:public class JsonCL
{
private int Code;
private String Text;
private int Id;setters; getters;
}
But what about the JSON, which contains arrays of data, and nested arrays? For example:
{\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\", \"data\":{\"groups\": [{\"key1\":\"value1\", \"nestedData\":[{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":\"value3\"},{\"key1\":\"value4\", \"key2\":\"value5\", \"key3\":\"value6\"}]},{\"key1\":\"value2\", \"nestedData\": [{\"key1\":\"value7\", \"key2\":\"value8\", \"key3\":\"value9\"},{\"key1\":\"value10\", \"key2\":\"value11\", \"key3\":\"value12\"}]}]}}}
How can I convert such JSON into java object? Thanks! -
Hi There is no problem to convert JSON which looks like this:
"{\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\"}}
to the following object:public class JsonCL
{
private int Code;
private String Text;
private int Id;setters; getters;
}
But what about the JSON, which contains arrays of data, and nested arrays? For example:
{\"response\": {\"Code\":200, \"Text\":\"Ok\", \"Id\":\"123\", \"data\":{\"groups\": [{\"key1\":\"value1\", \"nestedData\":[{\"key1\":\"value1\", \"key2\":\"value2\", \"key3\":\"value3\"},{\"key1\":\"value4\", \"key2\":\"value5\", \"key3\":\"value6\"}]},{\"key1\":\"value2\", \"nestedData\": [{\"key1\":\"value7\", \"key2\":\"value8\", \"key3\":\"value9\"},{\"key1\":\"value10\", \"key2\":\"value11\", \"key3\":\"value12\"}]}]}}}
How can I convert such JSON into java object? Thanks!check this: Json.Array @ Json.org greets Torsten
I never finish anyth...