當前位置: 首頁>>代碼示例>>Java>>正文


Java Utility.getStringPropertyAsJSON方法代碼示例

本文整理匯總了Java中com.facebook.internal.Utility.getStringPropertyAsJSON方法的典型用法代碼示例。如果您正苦於以下問題:Java Utility.getStringPropertyAsJSON方法的具體用法?Java Utility.getStringPropertyAsJSON怎麽用?Java Utility.getStringPropertyAsJSON使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.facebook.internal.Utility的用法示例。


在下文中一共展示了Utility.getStringPropertyAsJSON方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: createResponseFromObject

import com.facebook.internal.Utility; //導入方法依賴的package包/類
private static GraphResponse createResponseFromObject(
        GraphRequest request,
        HttpURLConnection connection,
        Object object,
        Object originalResult
) throws JSONException {
    if (object instanceof JSONObject) {
        JSONObject jsonObject = (JSONObject) object;

        FacebookRequestError error =
                FacebookRequestError.checkResponseAndCreateError(
                        jsonObject,
                        originalResult,
                        connection);
        if (error != null) {
            if (error.getErrorCode() == FacebookRequestErrorClassification.EC_INVALID_TOKEN
                    && Utility.isCurrentAccessToken(request.getAccessToken())) {
                AccessToken.setCurrentAccessToken(null);
            }
            return new GraphResponse(request, connection, error);
        }

        Object body = Utility.getStringPropertyAsJSON(
                jsonObject,
                BODY_KEY,
                NON_JSON_RESPONSE_PROPERTY);

        if (body instanceof JSONObject) {
            return new GraphResponse(request, connection, body.toString(), (JSONObject)body);
        } else if (body instanceof JSONArray) {
            return new GraphResponse(request, connection, body.toString(), (JSONArray)body);
        }
        // We didn't get a body we understand how to handle, so pretend we got nothing.
        object = JSONObject.NULL;
    }

    if (object == JSONObject.NULL) {
        return new GraphResponse(request, connection, object.toString(), (JSONObject)null);
    } else {
        throw new FacebookException("Got unexpected object type in response, class: "
                + object.getClass().getSimpleName());
    }
}
 
開發者ID:eviltnan,項目名稱:kognitivo,代碼行數:44,代碼來源:GraphResponse.java

示例2: checkResponseAndCreateError

import com.facebook.internal.Utility; //導入方法依賴的package包/類
static FacebookRequestError checkResponseAndCreateError(JSONObject singleResult,
        Object batchResult, HttpURLConnection connection) {
    try {
        if (singleResult.has(CODE_KEY)) {
            int responseCode = singleResult.getInt(CODE_KEY);
            Object body = Utility.getStringPropertyAsJSON(singleResult, BODY_KEY,
                    Response.NON_JSON_RESPONSE_PROPERTY);

            if (body != null && body instanceof JSONObject) {
                JSONObject jsonBody = (JSONObject) body;
                // Does this response represent an error from the service? We might get either an "error"
                // with several sub-properties, or else one or more top-level fields containing error info.
                String errorType = null;
                String errorMessage = null;
                int errorCode = INVALID_ERROR_CODE;
                int errorSubCode = INVALID_ERROR_CODE;

                boolean hasError = false;
                if (jsonBody.has(ERROR_KEY)) {
                    // We assume the error object is correctly formatted.
                    JSONObject error = (JSONObject) Utility.getStringPropertyAsJSON(jsonBody, ERROR_KEY, null);

                    errorType = error.optString(ERROR_TYPE_FIELD_KEY, null);
                    errorMessage = error.optString(ERROR_MESSAGE_FIELD_KEY, null);
                    errorCode = error.optInt(ERROR_CODE_FIELD_KEY, INVALID_ERROR_CODE);
                    errorSubCode = error.optInt(ERROR_SUB_CODE_KEY, INVALID_ERROR_CODE);
                    hasError = true;
                } else if (jsonBody.has(ERROR_CODE_KEY) || jsonBody.has(ERROR_MSG_KEY)
                        || jsonBody.has(ERROR_REASON_KEY)) {
                    errorType = jsonBody.optString(ERROR_REASON_KEY, null);
                    errorMessage = jsonBody.optString(ERROR_MSG_KEY, null);
                    errorCode = jsonBody.optInt(ERROR_CODE_KEY, INVALID_ERROR_CODE);
                    errorSubCode = jsonBody.optInt(ERROR_SUB_CODE_KEY, INVALID_ERROR_CODE);
                    hasError = true;
                }

                if (hasError) {
                    return new FacebookRequestError(responseCode, errorCode, errorSubCode,
                            errorType, errorMessage, jsonBody, singleResult, batchResult, connection);
                }
            }

            // If we didn't get error details, but we did get a failure response code, report it.
            if (!HTTP_RANGE_SUCCESS.contains(responseCode)) {
                return new FacebookRequestError(responseCode, INVALID_ERROR_CODE,
                        INVALID_ERROR_CODE, null, null,
                        singleResult.has(BODY_KEY) ?
                                (JSONObject) Utility.getStringPropertyAsJSON(
                                        singleResult, BODY_KEY, Response.NON_JSON_RESPONSE_PROPERTY) : null,
                        singleResult, batchResult, connection);
            }
        }
    } catch (JSONException e) {
        // defer the throwing of a JSONException to the graph object proxy
    }
    return null;
}
 
開發者ID:MobileDev418,項目名稱:AndroidBackendlessChat,代碼行數:58,代碼來源:FacebookRequestError.java


注:本文中的com.facebook.internal.Utility.getStringPropertyAsJSON方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。