public class MainActivity extends ActionBarActivity { TextView textView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); textView = (TextView)findViewById(R.id.hello_world); Cat murzik = new Cat(); murzik.name = "Мурзик"; murzik.age = 9; murzik.color = Color.BLACK; GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create(); textView.setText(gson.toJson(murzik)); } } public class Cat { public String name; public int age; public int color; public Cat(){ } }
The result is
{"name":"Мурзик","color":-16777216,"age":9}
Tell me how to get this result
{"murzik":[{"name":"Мурзик","color":-16777216,"age":9}]}