static public ImageryMetaDataResource getInstanceFromJSON ( final String a_jsonContent ) throws Exception { if ( a_jsonContent == null ) { throw new Exception ( "JSON to parse is null" ) ; } /// response code should be 200 and authorization should be valid (valid BingMap key) final JSONObject jsonResult = new JSONObject ( a_jsonContent ) ; final int statusCode = jsonResult . getInt ( STATUS_CODE ) ; if ( statusCode != 200 ) { throw new Exception ( "Status code = " + statusCode ) ; } if ( AUTH_RESULT_CODE_VALID . compareToIgnoreCase ( jsonResult . getString ( AUTH_RESULT_CODE ) ) != 0 ) { throw new Exception ( "authentication result code = " + jsonResult . getString ( AUTH_RESULT_CODE ) ) ; } // get first valid resource information final JSONArray resultsSet = jsonResult . getJSONArray ( RESOURCE_SETS ) ; if ( resultsSet == null || resultsSet . length ( ) < 1 ) { throw new Exception ( "No results set found in json response" ) ; } if ( resultsSet . getJSONObject ( 0 ) . getInt ( ESTIMATED_TOTAL ) <= 0 ) { throw new Exception ( "No resource found in json response" ) ; } final JSONObject resource = resultsSet . getJSONObject ( 0 ) . getJSONArray ( RESOURCE ) . getJSONObject ( 0 ) ; return ImageryMetaDataResource . getInstanceFromJSON ( resource , jsonResult ) ; }
Parse a JSON string containing ImageryMetaData response