Changeset 6010


Ignore:
Timestamp:
02/23/15 11:00:15 (9 years ago)
Author:
Twan Goosen
Message:

Fixed error in parsing Handle API JSON response

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vlo/trunk/vlo-web-app/src/main/java/eu/clarin/cmdi/vlo/service/handle/impl/HandleRestApiClient.java

    r4983 r6010  
    3333 * Service that connects to the handle.net REST API and retrieves the URL for a
    3434 * given handle.
    35  * 
     35 *
    3636 * Consider re-implementing using the handle API
    3737 *
     
    9999        // The handle API returns a JSON structure with a number of handle
    100100        // record fields. We are only interested in the value at
    101         // values[x].data where values[x].type == 'URL'
     101        // values[x].data.value where values[x].type == 'URL'
    102102
    103103        final JSONObject jsonResponse = new JSONObject(jsonString);
     
    106106            final JSONObject object = valuesArray.getJSONObject(i);
    107107            final String type = object.getString("type");
    108             if ("URL".equals(type)) {
    109                 // the field we were looking for
    110                 return object.getString("data");
     108            if ("URL".equals(type) && object.has("data")) {
     109                final JSONObject data = object.getJSONObject("data");
     110                if (data.has("value")) {
     111                    // the field we were looking for
     112                    return data.getString("value");
     113                }
    111114            }
    112115        }
Note: See TracChangeset for help on using the changeset viewer.