1

Json File. I have some question, how to get specific details in json.

[
{
"job": [
  {
    "id": 180066,
    "pending_update": false,
    "order_details": [
      {
        "order_id": 180066,
        "id": 69015
      },
      {
        "order_id": 180066,
        "id": 69016
      }
    ],
    "order_attempts": [
      {
        "order_id": 180066,
        "id": 349,
        "order_attempts_images": [
          {
            "order_attempt_id": 349,
            "id": 324
          }
        ]
      }
    ]
  },
  {
    "id": 180067,
    "pending_update": false,
    "order_attempts": [
      {
        "order_id": 180067,
        "id": 348,
        "order_attempts_images": [
          {
            "order_attempt_id": 348,
            "id": 323
          }
        ]
      }
    ]
  }
]

This json format very complicated for me.. How i can get id (job) , order_id (order_details) and order_attempt_id (order_attempts) for each job id in android Java.

A. Shukri
  • 115
  • 1
  • 8
  • Have you look at http://stackoverflow.com/questions/17136769/how-to-parse-jsonarray-in-android ? – Sun Maung Oo Nov 24 '16 at 04:24
  • Yes ..already saw on that answer.. but i confuse because this Json file start with [ which represent array.. – A. Shukri Nov 24 '16 at 04:34
  • It is actually the same, but instead of `JSONObject jsonResponse = new JSONObject(JSON);` you have to modify your code to `JSONArray jsonResponse = new JSONArray(JSON);` – HendraWD Nov 24 '16 at 04:39
  • You can also make use of JSON parser library, like Gson(https://github.com/google/gson), fastjson(https://github.com/alibaba/fastjson), etc. – HendraWD Nov 24 '16 at 04:42
  • Ok i already change .. Thank you so much .. i got that array.. but from that array how i can get object which is job ? – A. Shukri Nov 24 '16 at 04:48
  • JSONArray jsonResponse = new JSONArray(JSON); String results =jsonResponse.getJSONObject(0).getString("id"); But I cant get id job .. – A. Shukri Nov 24 '16 at 05:05
  • you have array of objects, which has another array in `job` field. So you have to do `JSONArray jsonResponse = new JSONArray(JSON); JSONArray job = jsonRestonce.getJSONObject(0).getJSONObject("job"); String results =job.getJSONObject(0).getString("id");`. Something like this – Vladyslav Matviienko Nov 24 '16 at 06:10
  • Vlad Matvienko .. I just test code like you said but cant get the id of job ... – A. Shukri Nov 24 '16 at 06:39

0 Answers0