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


Java JSONObject.getString方法代碼示例

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


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

示例1: dispatchEvent

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void dispatchEvent(JSONObject json, int sequence) {
    String id = json.getString("id");
    boolean unavailable = json.has("unavailable") && json.getBoolean("unavailable");

    Guild guild = (Guild) identity.getGuild(id);
    if (guild == null) {
        logger.log(LogLevel.FETAL, "[UNKNOWN GUILD] [GUILD_DELETE_EVENT]");
        return;
    }

    if (unavailable) {
        guild.setUnavailable(true);
        dispatchEvent(new GuildUnavailableEvent(identity, sequence, guild));
    } else {
        identity.removeGuild(id);
        dispatchEvent(new GuildDeleteEvent(identity, sequence, guild, OffsetDateTime.now()));
    }
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:20,代碼來源:GuildDeleteEventHandler.java

示例2: setupContacts

import org.json.JSONObject; //導入方法依賴的package包/類
public void setupContacts(JSONObject key) {
    JSONArray array = key.getJSONArray("private_channels");
    for (int i = 0; i < array.length(); i++) {
        JSONObject item = array.getJSONObject(i);
        JSONObject contact = item.getJSONObject("recipient");

        String id = contact.getString("id");

        if (item.getString("id").equals(api.getSelfInfo().getId()))
            api.setAs(contact.getString("id"));

        UserImpl userImpl = new UserImpl(contact.getString("username"), id, item.getString("id"), api);
        userImpl.setAvatar(contact.isNull("avatar") ? "" : "https://cdn.discordapp.com/avatars/" + id + "/" +
                contact.getString("avatar") + ".jpg");
        userImpl.setAvatarId(contact.isNull("avatar") ? "" : userImpl.getId());

        api.getAvailableDms().add(userImpl);
    }
}
 
開發者ID:discord-java,項目名稱:discord.jar,代碼行數:20,代碼來源:ReadyPoll.java

示例3: parseStatus

import org.json.JSONObject; //導入方法依賴的package包/類
private void parseStatus(String result){
	try {
		JSONObject json = new JSONObject(result);
		String status = json.getString("STATUS");
		rejected = json.getString("REJECTNO");
		if(status.equalsIgnoreCase("SUCCESS")){
			setResult(1001);
			sendNotification();
		}else if(status.equalsIgnoreCase("Already exist")){
			comman.alertDialog(AddNewMembers.this,getString(R.string.group_already_exist_head),getString(R.string.group_already_exist));
			return;
		}else{
			comman.alertDialog(AddNewMembers.this,getString(R.string.group_already_exist_head),getString(R.string.group_already_exist_error));
			return;
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:20,代碼來源:AddNewMembers.java

示例4: UIEvent

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Constructs a UIEvent from the JSON serialized representation.
 *
 * @param json The serialized UIEvent.
 * @throws JSONException
 */
public UIEvent(JSONObject json) throws JSONException {
    super(TYPE_UI, json);
    String element = json.getString(JSON_ELEMENT);
    try {
        mUiElement = validateUiElement(element);
    } catch (IllegalArgumentException e) {
        throw new JSONException("Invalid UI element: " + element);
    }
    if (mUiElement != ELEMENT_CATEGORY && TextUtils.isEmpty(mBlockId)) {
        throw new JSONException("UI element " + mUiElement + " requires " + JSON_BLOCK_ID);
    }
    this.mOldValue = json.optString(JSON_OLD_VALUE);  // Rarely used.
    this.mNewValue = json.optString(JSON_NEW_VALUE);
    if (mUiElement != ELEMENT_CATEGORY && mUiElement != ELEMENT_CLICK
            && TextUtils.isEmpty(mNewValue)) {
        throw new JSONException("UI element " + mUiElement + " requires " + JSON_NEW_VALUE);
    }
}
 
開發者ID:Axe-Ishmael,項目名稱:Blockly,代碼行數:25,代碼來源:BlocklyEvent.java

示例5: buttonClicked

import org.json.JSONObject; //導入方法依賴的package包/類
@JavascriptInterface
public void buttonClicked(String jsonString) {
    try {
        final JSONObject json = new JSONObject(jsonString);
        final JSONObject result = new JSONObject().put("id", json.getString("id"));

        if (json.has("buttonId")) {
            final String buttonId = json.getString("buttonId");
            coreSdkHandler.post(new Runnable() {
                @Override
                public void run() {
                    repository.add(new ButtonClicked(campaignId, buttonId, System.currentTimeMillis()));
                }
            });
            result.put("success", true);
        } else {
            result.put("success", false)
                    .put("error", "Missing buttonId!");
        }
        sendResult(result);
    } catch (JSONException je) {
        EMSLogger.log(MobileEngageTopic.IN_APP_MESSAGE, "Exception occurred, exception: %s json: %s", je, jsonString);
    }
}
 
開發者ID:emartech,項目名稱:android-mobile-engage-sdk,代碼行數:25,代碼來源:IamJsBridge.java

示例6: parseAttachmentsJSON

import org.json.JSONObject; //導入方法依賴的package包/類
private static List<Attachment> parseAttachmentsJSON(JSONObject attachmentsJSONObject) throws JSONException {
    List<Attachment> attachmentList = new ArrayList<>();

    JSONArray listJSONArray = attachmentsJSONObject.getJSONArray("List");
    int jsonArraySize = attachmentsJSONObject.getInt("Size");

    for (int index = 0; index < jsonArraySize; index++) {
        JSONObject listJSONObject = listJSONArray.getJSONObject(index);
        String name = listJSONObject.getString("Name");
        String link = listJSONObject.getString("Link");

        attachmentList.add(new Attachment(name, link));
    }

    return attachmentList;
}
 
開發者ID:DSM-DMS,項目名稱:DMS,代碼行數:17,代碼來源:JSONParser.java

示例7: requestDataFiles

import org.json.JSONObject; //導入方法依賴的package包/類
private void requestDataFiles(JSONObject objFormat) throws JSONException {
    // objFormat has the list of data files for the OBJ format (OBJ file, MTL file, textures).
    // We will use a AsyncFileDownloader to download all those files.
    mFileDownloader = new AsyncFileDownloader();

    // The "root file" is the OBJ.
    JSONObject rootFile = objFormat.getJSONObject("root");
    mFileDownloader.add(rootFile.getString("relativePath"), rootFile.getString("url"));

    // The "resource files" are the MTL file and textures.
    JSONArray resources = objFormat.getJSONArray("resources");
    for (int i = 0; i < resources.length(); i++) {
        JSONObject resourceFile = resources.getJSONObject(i);
        String path = resourceFile.getString("relativePath");
        String url = resourceFile.getString("url");
        // For this example, we only care about OBJ and PNG files.
        if (path.toLowerCase().endsWith(".obj") || path.toLowerCase().endsWith(".png")) {
            mFileDownloader.add(path, url);
        }
    }

    // Now start downloading the data files. When this is done, the callback will call
    // processDataFiles().
    Log.d(TAG, "Starting to download data files, # files: " + mFileDownloader.getEntryCount());
    mFileDownloader.start(mBackgroundThreadHandler, new AsyncFileDownloader.CompletionListener() {
        @Override
        public void onPolyDownloadFinished(AsyncFileDownloader downloader) {
            if (downloader.isError()) {
                Log.e(TAG, "Failed to download data files for asset.");
                return;
            }
            // Signal to the GL thread that download is complete, so it can go ahead and
            // import the model.
            Log.d(TAG, "Download complete, ready to import model.");
            mReadyToImport = true;
        }
    });
}
 
開發者ID:googlevr,項目名稱:poly-sample-android,代碼行數:39,代碼來源:HelloArActivity.java

示例8: getAccessToken

import org.json.JSONObject; //導入方法依賴的package包/類
private String getAccessToken() {
    String token = "";
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(mContext);
    String token_string = sharedPreferences.getString("trakt_token", "");
    if(token_string.equals("")) return "";
    try {
        JSONObject json_token = new JSONObject(token_string);
        token = json_token.getString("access_token");
    } catch (JSONException e) {
        e.printStackTrace();
    }

    return token;
}
 
開發者ID:ad-on-is,項目名稱:chilly,代碼行數:15,代碼來源:Chilly.java

示例9: testUpdateWithEmptyValues

import org.json.JSONObject; //導入方法依賴的package包/類
public void testUpdateWithEmptyValues() throws Exception
{
    JSONObject item = createPost("test", "test", null, false, 200);
    String name = item.getString("name");
    assertEquals(false, item.getBoolean("isUpdated"));
    
    item = updatePost(item.getString("name"), null, null, null, false, 200);
    assertEquals("", item.getString("title"));
    assertEquals("", item.getString("content"));
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:11,代碼來源:BlogServiceTest.java

示例10: getOldFileVersionStr

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 *
 * @param file 文件路徑
 * @param versionKey 下載版本文件的url
 * @return 舊的版本文件中file的版本號 是文件的md5值
 * @return 新版本文件中file的版本號 是文件的crc32值
 * @throws JSONException
 */
private String getOldFileVersionStr(String file, String versionKey) throws JSONException {
    String v ="";

    String versionTxt = cookie.getCookie(versionKey);//得到sp中保存的cookievalue實體中的版本文件 json字符串,和上次版本的版本文件比較,文件的版本號
    //如果本地本來就沒有下載version.txt文件,那麽return "",即下載本次的版本文件
    if (versionTxt.equals("")){
        return "";
    }

    JSONObject json = new JSONObject(versionTxt);
    json = json.getJSONObject("update");
    Iterator<String> it = json.keys();

    boolean lock = true;
    while (it.hasNext()) {
        String str = (String) it.next();
        JSONArray array = json.getJSONArray(str);
        lock = true;
        for (int i = 0; i < array.length(); i++) {
            JSONObject obj = array.getJSONObject(i);
            v = obj.getString("ver");//是文件的crc32值,是String類型
            String p = obj.getString("file");

            if (p.equals(file)) {//如果舊的版本文件中file文件名稱和新的版本文件中file文件名稱相同
                lock = false;
                break;
            }
        }

        if (!lock) {
            break;
        }
    }
    if (lock) {
        v = "0";
    }
    return v;
}
 
開發者ID:AlpacaNotSheep,項目名稱:hybrid,代碼行數:47,代碼來源:SyncVersion.java

示例11: parseJson

import org.json.JSONObject; //導入方法依賴的package包/類
private void parseJson(String result){
	try {
		JSONObject json = new JSONObject(result);
		StatusId = json.getString("STATUS");
		shared.saveSharedData("State", StatusId);
		String mOTP = json.getString("OTP");
		shared.saveSharedData("mOTP", mOTP);
		if(StatusId.equalsIgnoreCase("0")){
			//If phone number not exist.fill all the parameter manually
			 //senOTPJson("+"+countryPrefix+edtMobile.getText().toString().trim());
			sendComposedSms(countryPrefix+edtMobile.getText().toString().trim(), mOTP+" "+getString(R.string.verify_otp));
			/*Intent i = new Intent(SignIn.this, VerifyOTP.class);
			i.putExtra("State", StatusId);
			i.putExtra("MobileNum", edtMobile.getText().toString().trim());
			i.putExtra("CountryCode", countryPrefix);
			i.putExtra("CountryName", countryName);
			startActivity(i);*/
			//SignIn.this.finish();
		}else if(StatusId.equalsIgnoreCase("2")){
			//If user already registered login  & enter OTP
			sendComposedSms(countryPrefix+edtMobile.getText().toString().trim(), mOTP+" "+getString(R.string.verify_otp));
			/*Intent i = new Intent(SignIn.this, VerifyOTP.class);
			i.putExtra("State", StatusId);
			i.putExtra("MobileNum", edtMobile.getText().toString().trim());
			i.putExtra("CountryCode", countryPrefix);
			i.putExtra("CountryName", countryName);
			startActivity(i);
			SignIn.this.finish();*/
		}
	} catch (Exception e) {
		// TODO: handle exception
	}
}
 
開發者ID:mityung,項目名稱:XERUNG,代碼行數:34,代碼來源:SignIn.java

示例12: handleErrorResponse

import org.json.JSONObject; //導入方法依賴的package包/類
private void handleErrorResponse(JSONObject response) {
    if (response.has("code")) {
        if (!(response.get("code") instanceof Integer)) return;
        ErrorResponse errorResponse = ErrorResponse.getByKey(response.getInt("code"));
        if (errorResponse != ErrorResponse.UNKNOWN) {
            throw new ErrorResponseException(errorResponse);
        } else {
            throw new ErrorResponseException(response.getInt("code"), response.getString("message"));
        }
    }
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:12,代碼來源:Requester.java

示例13: getObjectFromJsonObject

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * Create a concrete object from the JSONObject received.
 *
 * The class to instanciate is deduced from the value of the "type" field of
 * JSONObject.
 * @param jsonData
 * @return the object newly created
 */
private JSONable getObjectFromJsonObject(final JSONObject jsonData) {
    JSONable result = null;
    switch (jsonData.getString("type")) {

        case "Block":
            result = new Block(jsonData);
            break;

        case "BlockChain":
            result = new BlockChain(jsonData);
            break;

        case "Address":
            result = new Address(jsonData);
            break;

        case "Transaction":
            result = new Transaction(jsonData);
            break;

        case "TestStr":
            result = new TestStrJSONable(jsonData);
            break;

        case "Message":
            result = new Message(jsonData);
            break;
    }

    return result;
}
 
開發者ID:StanIsAdmin,項目名稱:CrashCoin,代碼行數:40,代碼來源:AbstractConnection.java

示例14: extractBusStopsFromJson

import org.json.JSONObject; //導入方法依賴的package包/類
private List<BusStop> extractBusStopsFromJson(String realTimeTransitInformationJson) {

        // If the JSON is empty, return null and exit early.
        if (TextUtils.isEmpty(realTimeTransitInformationJson)) {
            return null;
        }

        List<BusStop> busStopList = new ArrayList<>();

        try {

            JSONArray busStopArray = new JSONArray(realTimeTransitInformationJson);

            for (int i = 0; i < busStopArray.length(); i++) {
                JSONObject currentBusStop = busStopArray.getJSONObject(i);

                String name = null;
                if (currentBusStop.has("Name")) {
                    name = currentBusStop.getString("Name");
                }

                String routes = null;
                if (currentBusStop.has("Routes")) {
                    routes = currentBusStop.getString("Routes");
                }

                String stopNumber = null;
                if (currentBusStop.has("StopNo")) {
                    stopNumber = currentBusStop.getString("StopNo");
                }

                String atStreet = null;
                if (currentBusStop.has("AtStreet")) {
                    atStreet = currentBusStop.getString("AtStreet");
                }

                String onStreet = null;
                if (currentBusStop.has("OnStreet")) {
                    onStreet = currentBusStop.getString("OnStreet");
                }


                busStopList.add(new BusStop(name, routes, stopNumber, atStreet, onStreet));
            }

        } catch (JSONException e) {
            e.printStackTrace();
        }

        return busStopList;
    }
 
開發者ID:joshvocal,項目名稱:TransLinkMe-App,代碼行數:52,代碼來源:BusStopRadiusLoader.java

示例15: toJavaCandidate

import org.json.JSONObject; //導入方法依賴的package包/類
IceCandidate toJavaCandidate(JSONObject json) throws JSONException {
  return new IceCandidate(
      json.getString("id"), json.getInt("label"), json.getString("candidate"));
}
 
開發者ID:Piasy,項目名稱:AppRTC-Android,代碼行數:5,代碼來源:WebSocketRTCClient.java


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