JSONObject jsonObj = null; try { jsonObj = XML.toJSONObject(sampleXml); } catch (JSONException e) { Log.e("JSON exception", e.getMessage()); e.printStackTrace(); } Log.d("XML", sampleXml); Log.d("JSON", jsonObj.toString());
public Object get(String key) { if(!this.has(key)) { return null; } try { return this.json.get(key); } catch (JSONException e) { LOG.debug(e.getMessage(),e); return null; } }
/** * * @param source A string beginning with { (left brace) and ending with } (right brace). * @throws GfJsonException - If there is a syntax error in the source string or a duplicated key. */ public GfJsonObject(String source) throws GfJsonException { try { this.jsonObject = new JSONObject(source); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
public GfJsonObject put(String key, Map<?, ?> value) throws GfJsonException { try { jsonObject.put(key, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * * @return this GfJsonObject * @throws GfJsonException If the object contains an invalid number. */ public String toIndentedString(int indentFactor) throws GfJsonException { try { return jsonObject.toString(indentFactor); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
/** * @return this GfJsonArray * @throws GfJsonException If the index is negative or if the value is not finite. */ public GfJsonArray put(int index, Collection<?> value) throws GfJsonException { try { this.jsonArray.put(index, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * @return this GfJsonArray * @throws GfJsonException If the index is negative or if the the value is an invalid number. */ public GfJsonArray put(int index, Map<?, ?> value) throws GfJsonException { try { this.jsonArray.put(index, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * Get the object value associated with an index. * * @return An object value. * @throws GfJsonException If there is no value for the index. */ public Object get(int index) throws GfJsonException { try { return this.jsonArray.get(index); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
protected String getClientState(String authId) { JSONObject param = new JSONObject(); try { param.put(LoginLogger.EVENT_PARAM_AUTH_LOGGER_ID, authId); param.put(LoginLogger.EVENT_PARAM_METHOD, getNameForLogging()); putChallengeParam(param); } catch (JSONException e) { Log.w("LoginMethodHandler", "Error creating client state json: " + e.getMessage()); } return param.toString(); }
/** * @return this GfJsonArray * @throws GfJsonException If the index is negative or if the the value is an invalid number. */ public GfJsonArray put(int index, Object value) throws GfJsonException { try { this.jsonArray.put(index, extractInternalForGfJsonOrReturnSame(value)); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
public GfJsonObject getJSONObject(int index) throws GfJsonException { try { return new GfJsonObject(jsonArray.getJSONObject(index)); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } }
public Object get(String key) { if(!this.has(key)) { return null; } try { return this.json.get(key); } catch (JSONException e) { LOG.debug(e.getMessage(),e); return null; } }
/** * * @return this GfJsonObject * @throws GfJsonException If the value is a non-finite number. */ public GfJsonObject put(String key, Collection<?> value) throws GfJsonException { try { jsonObject.putOpt(key, value); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
@Override public void onSuccess(JSONObject userInfo) { try { String userId = userInfo.getString("id"); result.putString(NativeProtocol.EXTRA_USER_ID, userId); onComplete(request, result); } catch (JSONException ex) { loginClient.complete(LoginClient.Result.createErrorResult( loginClient.getPendingRequest(), "Caught exception", ex.getMessage())); } }
public GfJsonObject putJSONArray(String key, GfJsonArray value) throws GfJsonException { try { jsonObject.putOpt(key, value.getInternalJsonArray()); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
private static Bundle create( ShareMessengerOpenGraphMusicTemplateContent openGraphMusicTemplateContent, boolean dataErrorsFatal) { Bundle params = createBaseParameters(openGraphMusicTemplateContent, dataErrorsFatal); try { MessengerShareContentUtility.addOpenGraphMusicTemplateContent( params, openGraphMusicTemplateContent); } catch (JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided " + "ShareMessengerOpenGraphMusicTemplateContent: " + e.getMessage()); } return params; }
private static Bundle create( ShareMessengerMediaTemplateContent mediaTemplateContent, boolean dataErrorsFatal) { Bundle params = createBaseParameters(mediaTemplateContent, dataErrorsFatal); try { MessengerShareContentUtility.addMediaTemplateContent( params, mediaTemplateContent); } catch (JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided " + "ShareMessengerMediaTemplateContent: " + e.getMessage()); } return params; }
private static Bundle create( ShareMessengerGenericTemplateContent genericTemplateContent, boolean dataErrorsFatal) { Bundle params = createBaseParameters(genericTemplateContent, dataErrorsFatal); try { MessengerShareContentUtility.addGenericTemplateContent( params, genericTemplateContent); } catch (JSONException e) { throw new FacebookException( "Unable to create a JSON Object from the provided " + "ShareMessengerGenericTemplateContent: " + e.getMessage()); } return params; }
public GfJsonObject putAsJSONObject(String key, Object value) throws GfJsonException { try { Object internalJsonObj = extractInternalForGfJsonOrReturnSame(value); if (internalJsonObj == value) { GfJsonObject jsonObj = new GfJsonObject(value); internalJsonObj = jsonObj.getInternalJsonObject(); } jsonObject.put(key, internalJsonObj); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }
/** * * @return this GfJsonObject * @throws GfJsonException If the value is a non-finite number. */ public GfJsonObject putOpt(String key, Object value) throws GfJsonException { try { jsonObject.putOpt(key, extractInternalForGfJsonOrReturnSame(value)); } catch (JSONException e) { throw new GfJsonException(e.getMessage()); } return this; }