-3

"working_days": [ { "day_id": 2, "from": 11, "to": 22 }, { "day_id": 3, "from": 10, "to": 23 } ],

that 's part of the script i need to post i'm using volley with Gson can anybody help

{
    "userId": 2,
    "token": "bdajkvnbadkvda1ad1fadf4ad5f1da5",
    "name": "Center 123",
    "address": "12 Ramsis Str.,",
    "lat": "30.31194946131",
    "long": "30.31194946131",
    "location": "Assute",
    "phone": "032365653232",
    "owner_name": "Ahmed",
    "owner_number": "164956465464",
    "registry_number": "2161312",
    "taxation_card": "2326-66321",
    "contract_code": "1211132",
    "remark": "Beside phrmacy",
    "working_days": [
       {
          "day_id": 2,
          "from": 11,
          "to": 22
        },
         {
          "day_id": 3,
          "from": 10,
          "to": 23
        }
    ],
    "images": [
      {
       "url": "uploads/center/s51fdf5df1d5.png"
       },
       {
        "url": "uploads/center/s5d1f6d645616.png"
        }
    ]
   }  

2 Answers2

0

use www.jsonschema2pojo.org to create Java objects and parse it with Gson library: http://www.vogella.com/tutorials/JavaLibrary-Gson/article.html

Alex Shutov
  • 3,217
  • 2
  • 13
  • 11
0

You can use volley to parse your response easily.

try {

          JSONObject jsonObject = new JSONObject(your_response);
          int userId = jsonObject.getInt("userId");
          String token = jsonObject.getString("token");
                            .
                            .
                            .
                            .

           JSONArray working_days = jsonObject.getJSONArray("working_days");

            for (int i = 0; i < working_days.length(); i++) {
                      int day_id = jsonObject.getInt("day_id");
                      int from = jsonObject.getInt("from");
                      int to = jsonObject.getInt("to");
            }


          JSONArray images = jsonObject.getJSONArray("images");

            for (int i = 0; i < working_days.length(); i++) {
                     int url = jsonObject.getInt("url");
            }

       } catch (JSONException e) {
          Log.e(TAG, "Your Boss is Calling");
       }
Amar Ilindra
  • 923
  • 2
  • 11
  • 30