当前位置: 首页>>代码示例>>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;未经允许,请勿转载。