0

I have this class:

    class Type{
        public int id;
        public String name;
    }

and I want to format object in JSON this way

    {[1,"superMarket"],[2,"restaurant "]}

and also put data from JSON to "Type" object

can some one help me please......

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
Medo Elkamaly
  • 2,508
  • 1
  • 20
  • 15

3 Answers3

2

You can get an easy to understand example for encoding and parsing json:

Android JSON Tutorial: Create and Parse JSON data

and

JSON in Android - Tutorial

Pratik Butani
  • 60,504
  • 58
  • 273
  • 437
AndyN
  • 1,742
  • 1
  • 15
  • 30
0

you nee to use a jasonArray and thee jsonObject ro do this.. you can viw this answer

Android create a JSON array of JSON Objects

Community
  • 1
  • 1
archetipo
  • 579
  • 4
  • 10
0

Type to JSON

JSONObject jsonObj = new JSONObject();
jsonObj.putString("id", id);
jsonObj.putString("name", name);

You can add as many jsonObjs to JSONArray.

JSON to Type

Type type = new Type();
type.setId(jsonObj.optString("id"));
type.setName(jsonObj.optString("name"));
R9J
  • 6,605
  • 4
  • 19
  • 25