I\'ve been looking for a while and want a way to sort a JSON object like this:
{\"results\": [
{
\"layerId\": 5,
\"layerName\": \"Pharmaceutical En
Parse these JSON to Collection of Objects and use comparator to sort it using your preferred field.
Example:
import com.google.gson.Gson;
class Person {
private int age;
private String name;
}
String json = "{'age':22,'name':'Jigar'}";
Gson gson = new Gson();
TestJsonFromObject obj = gson.fromJson(json, Person.class);
If you want to create JSON from Object.
Person p = new Person();
p.setName("Jigar");
p.setAge(22);
String jsonStr = new com.google.gson.Gson().toJson(obj);