当前位置: 首页>>代码示例>>Java>>正文


Java JSONObject.optString方法代码示例

本文整理汇总了Java中org.json.JSONObject.optString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.optString方法的具体用法?Java JSONObject.optString怎么用?Java JSONObject.optString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.json.JSONObject的用法示例。


在下文中一共展示了JSONObject.optString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.json.JSONObject; //导入方法依赖的package包/类
public static Geo parse(JSONObject jsonObject) {
    if (null == jsonObject) {
        return null;
    }
    
    Geo geo = new Geo();
    geo.longitude       = jsonObject.optString("longitude");
    geo.latitude        = jsonObject.optString("latitude");
    geo.city            = jsonObject.optString("city");
    geo.province        = jsonObject.optString("province");
    geo.city_name       = jsonObject.optString("city_name");
    geo.province_name   = jsonObject.optString("province_name");
    geo.address         = jsonObject.optString("address");
    geo.pinyin          = jsonObject.optString("pinyin");
    geo.more            = jsonObject.optString("more");
    
    return geo;
}
 
开发者ID:ligongzai,项目名称:QianXun,代码行数:19,代码来源:Geo.java

示例2: fillPageNavigations

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Fills page navigations.
 *
 * @param dataModel
 *            data model
 * @throws ServiceException
 *             service exception
 */
private void fillPageNavigations(final Map<String, Object> dataModel) throws ServiceException {
	Stopwatchs.start("Fill Navigations");
	try {
		logger.debug("Filling page navigations....");
		final List<JSONObject> pages = pageDao.getPages();

		for (final JSONObject page : pages) {
			if ("page".equals(page.optString(Page.PAGE_TYPE))) {
				final String permalink = page.optString(Page.PAGE_PERMALINK);

				page.put(Page.PAGE_PERMALINK, Latkes.getServePath() + permalink);
			}
		}

		dataModel.put(Common.PAGE_NAVIGATIONS, pages);
	} catch (final RepositoryException e) {
		logger.error("Fills page navigations failed", e);
		throw new ServiceException(e);
	} finally {
		Stopwatchs.end();
	}
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:31,代码来源:Filler.java

示例3: getIconResId

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Retrieves the resource ID of the app icon.
 *
 * @param settings A JSON dict containing the icon name.
 */
private int getIconResId(JSONObject settings) {
    Context context = getApplicationContext();
    Resources res   = context.getResources();
    String pkgName  = context.getPackageName();
    String icon     = settings.optString("icon", NOTIFICATION_ICON);

    // cordova-android 6 uses mipmaps
    int resId = getIconResId(res, icon, "mipmap", pkgName);

    if (resId == 0) {
        resId = getIconResId(res, icon, "drawable", pkgName);
    }

    return resId;
}
 
开发者ID:SUTFutureCoder,项目名称:localcloud_fe,代码行数:21,代码来源:ForegroundService.java

示例4: currentUserName

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Gets the current logged in user name with the specified request.
 *
 * @param request
 *            the specified request
 * @return the current user name or {@code null}
 */
public static String currentUserName(final HttpServletRequest request) {
	final HttpSession session = request.getSession(false);

	if (null != session) {
		final JSONObject user = (JSONObject) session.getAttribute(User.USER);

		return user.optString(User.USER_NAME);
	}

	return null;
}
 
开发者ID:daima,项目名称:solo-spring,代码行数:19,代码来源:Sessions.java

示例5: parse

import org.json.JSONObject; //导入方法依赖的package包/类
public static Attitude parse(JSONObject jsonObject) {
    if (null == jsonObject) {
        return null;
    }
    Attitude attitude = new Attitude();
    attitude.id = jsonObject.optLong("id", 0L);
    attitude.created_at = jsonObject.optString("created_at", "");
    attitude.attitude = jsonObject.optString("attitude", "");
    attitude.attitude_type = jsonObject.optInt("attitude_type", 0);
    attitude.last_attitude = jsonObject.optString("last_attitude", "");
    attitude.source_allowclick = jsonObject.optInt("source_allowclick", 0);
    attitude.source_type = jsonObject.optInt("source_type", 0);
    attitude.source = jsonObject.optString("source", "");
    attitude.user = User.parse(jsonObject.optJSONObject("user"));
    attitude.status = Status.parse(jsonObject.optJSONObject("status"));
    return attitude;
}
 
开发者ID:liying2008,项目名称:Simpler,代码行数:18,代码来源:Attitude.java

示例6: toIssue

import org.json.JSONObject; //导入方法依赖的package包/类
/**
 * Returns the parsed issue, never null
 */
public static Issue toIssue(WebService webService, JSONObject json) {
    String key = json.optString("key");
    if (key == null || key.isEmpty()) {
        throw new IllegalArgumentException("Invalid Json, missing key: " + json);
    }
    Issue issue = webService.getIssue(key, EMPTY_REQUEST);
    JSONObject fields = json.optJSONObject("fields");
    if (fields != null) {
        FieldMap fieldMap = issue.getFieldMap();
        for (String id : fields.keySet()) {
            Object val = fields.get(id);
            if (val == JSONObject.NULL) {
                val = null;
            }
            Field field = fieldMap.getFieldById(id);
            if (field == null) {
                field = new Field(issue, id, new Value(val));
                fieldMap.addField(field);
            } else if (!Objects.equals(val, field.getValue().get())) {
                field.getValue().set(val);
            }
        }
    }
    return issue;
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:29,代码来源:ConversionUtils.java

示例7: parse

import org.json.JSONObject; //导入方法依赖的package包/类
public static Card parse(JSONObject obj) {
    if (obj == null) {
        return null;
    }
    Card card = new Card();
    card.card_type = obj.optInt("card_type", 0);
    card.show_type = obj.optInt("show_type", 0);

    JSONArray cardGroups = obj.optJSONArray("card_group");
    if (cardGroups != null && cardGroups.length() > 0) {
        card.card_group = new ArrayList<>(cardGroups.length());
        for (int i = 0; i < cardGroups.length(); i++) {
            CardGroup cardGroup = CardGroup.parse(cardGroups.optJSONObject(i));
            if (cardGroup != null) {
                card.card_group.add(cardGroup);
            }
        }
    }
    card.openurl = obj.optString("openurl", "");

    card.mblog = MBlog.parse(obj.optJSONObject("mblog"));
    return card;
}
 
开发者ID:liying2008,项目名称:Simpler,代码行数:24,代码来源:Card.java

示例8: a

import org.json.JSONObject; //导入方法依赖的package包/类
private static /* synthetic */ a a(c cVar, a aVar) {
    if (aVar != null && "toast".equals(aVar.k)) {
        JSONObject jSONObject = aVar.m;
        CharSequence optString = jSONObject.optString(WidgetRequestParam.REQ_PARAM_COMMENT_CONTENT);
        int optInt = jSONObject.optInt(DownloadVideoTable.COLUMN_DURATION);
        int i = 1;
        if (optInt < 2500) {
            i = 0;
        }
        Toast.makeText(cVar.b, optString, i).show();
        new Timer().schedule(new e(cVar, aVar), (long) i);
    }
    return a.NONE_ERROR;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:15,代码来源:c.java

示例9: parseWith

import org.json.JSONObject; //导入方法依赖的package包/类
@Override
public void parseWith(@NonNull JSONObject data, @NonNull MVHelper resolver) {
    this.mCells.clear();
    id = data.optString(Card.KEY_ID, id == null ? "" : id);
    this.cardType = data.optString(Card.KEY_TYPE);
    // parsing header
    if (Utils.isSupportHeaderFooter(cardType)) {
        JSONObject header = data.optJSONObject(Card.KEY_HEADER);
        parseHeaderCell(resolver, header);
    }

    // parsing body
    JSONArray componentArray = data.optJSONArray(Card.KEY_ITEMS);
    if (componentArray != null) {
        final int cellLength = componentArray.length();
        for (int i = 0; i < cellLength; i++) {
            final JSONObject cellData = componentArray.optJSONObject(i);
            BaseCell cell = createCell(resolver, cellData, true);
            try {
                if (cell != null) {
                    cell.extras.put(MVResolver.KEY_INDEX, cell.pos);
                }
            } catch (JSONException e) {
            }
        }
    }
    // parsing footer
    if (Utils.isSupportHeaderFooter(cardType)) {
        JSONObject footer = data.optJSONObject(Card.KEY_FOOTER);
        parseFooterCell(resolver, footer);
    }

    JSONObject styleJson = data.optJSONObject(Card.KEY_STYLE);

    parseStyle(styleJson);
}
 
开发者ID:alibaba,项目名称:Tangram-Android,代码行数:37,代码来源:BannerEntityCard.java

示例10: SkuDetails

import org.json.JSONObject; //导入方法依赖的package包/类
public SkuDetails(String itemType, String jsonSkuDetails) throws JSONException {
    mItemType = itemType;
    mJson = jsonSkuDetails;
    JSONObject o = new JSONObject(mJson);
    mSku = o.optString("productId");
    mType = o.optString("type");
    mPrice = o.optString("price");
    mTitle = o.optString("title");
    mDescription = o.optString("description");
}
 
开发者ID:dmllr,项目名称:IdealMedia,代码行数:11,代码来源:SkuDetails.java

示例11: getConfigOption

import org.json.JSONObject; //导入方法依赖的package包/类
private static String getConfigOption(final JSONObject config, final String key, final String defaultVal) {
    if (config.has(key)) {
        return config.optString(key);
    } else if (defaultVal != null && !defaultVal.equals("")) {
        return defaultVal;
    } else {
        return null;
    }
}
 
开发者ID:jsayol,项目名称:cordova-plugin-firebase-sdk,代码行数:10,代码来源:Firebase.java

示例12: parseJsonBody

import org.json.JSONObject; //导入方法依赖的package包/类
@Override
protected void parseJsonBody(@NonNull JSONObject jsonBody) {
	super.parseJsonBody(jsonBody);
	mCollectionId = jsonBody.optString(ATTR_COL_ID);
	mFetchId = jsonBody.optString(ATTR_FETCH_ID);
	mDocuments = jsonBody.optString(ATTR_DOCS);
}
 
开发者ID:rapid-io,项目名称:rapid-io-android,代码行数:8,代码来源:Message.java

示例13: Purchase

import org.json.JSONObject; //导入方法依赖的package包/类
public Purchase(String itemType, String jsonPurchaseInfo, String signature) throws JSONException {
    mItemType = itemType;
    mOriginalJson = jsonPurchaseInfo;
    JSONObject o = new JSONObject(mOriginalJson);
    mOrderId = o.optString("orderId");
    mPackageName = o.optString("packageName");
    mSku = o.optString("productId");
    mPurchaseTime = o.optLong("purchaseTime");
    mPurchaseState = o.optInt("purchaseState");
    mDeveloperPayload = o.optString("developerPayload");
    mToken = o.optString("token", o.optString("purchaseToken"));
    mIsAutoRenewing = o.optBoolean("autoRenewing");
    mSignature = signature;
}
 
开发者ID:zacharee,项目名称:SystemUITuner2,代码行数:15,代码来源:Purchase.java

示例14: get

import org.json.JSONObject; //导入方法依赖的package包/类
public InputStream get(String key, String contentTag) throws IOException {
    File file = new File(this.directory, Utility.md5hash(key));

    FileInputStream input = null;
    try {
        input = new FileInputStream(file);
    } catch (IOException e) {
        return null;
    }

    BufferedInputStream buffered = new BufferedInputStream(input, Utility.DEFAULT_STREAM_BUFFER_SIZE);
    boolean success = false;

    try {
        JSONObject header = StreamHeader.readHeader(buffered);
        if (header == null) {
            return null;
        }

        String foundKey = header.optString(HEADER_CACHEKEY_KEY);
        if ((foundKey == null) || !foundKey.equals(key)) {
            return null;
        }

        String headerContentTag = header.optString(HEADER_CACHE_CONTENT_TAG_KEY, null);

        if ((contentTag == null && headerContentTag != null) ||
                (contentTag != null && !contentTag.equals(headerContentTag))) {
            return null;
        }

        long accessTime = new Date().getTime();
        Logger.log(LoggingBehavior.CACHE, TAG, "Setting lastModified to " + Long.valueOf(accessTime) + " for "
                + file.getName());
        file.setLastModified(accessTime);

        success = true;
        return buffered;
    } finally {
        if (!success) {
            buffered.close();
        }
    }
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:45,代码来源:FileLruCache.java

示例15: a

import org.json.JSONObject; //导入方法依赖的package包/类
public void a(JSONObject jSONObject, Response response) {
    String optString = jSONObject.optString("photo_url");
    this.b.a(new ay(this, jSONObject.optString("photo_key"), optString));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:5,代码来源:ax.java


注:本文中的org.json.JSONObject.optString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。