Obtener ID del campo Valor de carga útil JSON utilizando Java

Suraj Prasad:

Estoy tratando de obtener el identificador de campo para la continuación de carga útil sin embargo estoy atascado con el siguiente código. Necesito el valor de identificador de campo "70ce3705-0191-4ba4-a635-65108f1c3dde"

    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(jsonfilepath));
    JSONObject valid = (JSONObject) jsonObject.get("valid");
    JSONArray applications = (JSONArray) jsonObject.get("applications_added");

Carga útil:

{
    "valid": {
  "applications_added": [
    {
          "id": "f8ca0bda-a10c-4e8d-9c1b-6bfd24e93395",
      "status": "active",
      "custom_fields": [
          {
          "field_id": "70ce3705-0191-4ba4-a635-65108f1c3dde",
          "option_id": "db7bb12d-a26f-413e-b9e5-79af8c28b1e7"
        }

      ]
    }
  ]
}
    }
Gevorg Harutyunyan:

En su código en lugar de jsonObject.get ( "applications_added") que escribe sould valid.get ( "applications_added")

La solución completa para su problema.

    JSONParser parser = new JSONParser();
    JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(jsonfilepath));
    JSONObject valid = (JSONObject) jsonObject.get("valid");
    JSONArray applications = (JSONArray) valid.get("applications_added");
    JSONObject application  = (JSONObject)applications.get(0);
    JSONArray custom_fields = (JSONArray) application.get("custom_fields");
    JSONObject custom_field  = (JSONObject)custom_fields.get(0);
    String field_id = (String)custom_field.get("field_id");

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=349822&siteId=1
Recomendado
Clasificación