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


Java JSONObject.getJSONObject方法代碼示例

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


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

示例1: WeatherItem

import org.json.JSONObject; //導入方法依賴的package包/類
public WeatherItem(JSONObject root) {

        try {

            timestmp = root.getLong("dt");

            JSONObject main = root.getJSONObject("main");
            temp = main.getDouble("temp");
            tempMin = main.getDouble("temp_min");
            tempMax = main.getDouble("temp_max");
            pressure = main.getDouble("pressure");
            humadity = main.getInt("humidity");

            JSONArray weather = root.getJSONArray("weather");
            JSONObject weatherObj = weather.getJSONObject(0);
            description = weatherObj.getString("description");
            iconUrl = weatherObj.getString("icon");
            id= weatherObj.getInt("id");
            mainDesc= weatherObj.getString("main");

            JSONObject wind = root.getJSONObject("wind");
            windSpeed = wind.getDouble("speed");
            windDeg = wind.getDouble("deg");

            isSuccess = true;
        } catch (JSONException e) {
            isSuccess = false;
            error = e + "";
        }

    }
 
開發者ID:shivam301296,項目名稱:True-Weather,代碼行數:32,代碼來源:WeatherItem.java

示例2: fromJSON

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void fromJSON(JSONObject object, Database catalog_db) throws JSONException {
    JSONArray jsonArr = object.getJSONArray(Members.HISTOGRAM.name());
    this.histogram = new long[jsonArr.length()];
    this.clear();
    for (int i = 0; i < this.histogram.length; i++) {
        long delta = jsonArr.getLong(i);
        if (delta != NULL_COUNT) this.put(i, delta);
    } // FOR
    
    if (object.has(Members.DEBUG.name())) {
        if (this.debug_names == null) {
            this.debug_names = new TreeMap<Object, String>();
        } else {
            this.debug_names.clear();
        }
        JSONObject jsonObj = object.getJSONObject(Members.DEBUG.name());
        for (String key : CollectionUtil.iterable(jsonObj.keys())) {
            String label = jsonObj.getString(key);
            this.debug_names.put(Integer.valueOf(key), label);
        }
    }
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:24,代碼來源:FastIntHistogram.java

示例3: ImageLine

import org.json.JSONObject; //導入方法依賴的package包/類
ImageLine(JSONObject jsonLine) throws JSONException {
    mTextFields = new ArrayList<TextField>();

    JSONArray textValues = jsonLine.getJSONArray(ANSWERS_JSON_TEXT);
    for (int i = 0; i < textValues.length(); i++) {
        mTextFields.add(new TextField(textValues.getJSONObject(i)));
    }

    mAdditionalText = jsonLine.has(ANSWERS_JSON_ADDITIONAL_TEXT)
            ? new TextField(jsonLine.getJSONObject(ANSWERS_JSON_ADDITIONAL_TEXT))
            : null;

    mStatusText = jsonLine.has(ANSWERS_JSON_STATUS_TEXT)
            ? new TextField(jsonLine.getJSONObject(ANSWERS_JSON_STATUS_TEXT))
            : null;

    mImage = jsonLine.has(ANSWERS_JSON_IMAGE)
            ? jsonLine.getJSONObject(ANSWERS_JSON_IMAGE).getString(ANSWERS_JSON_IMAGE_DATA)
            : null;
}
 
開發者ID:rkshuai,項目名稱:chromium-for-android-56-debug-video,代碼行數:21,代碼來源:SuggestionAnswer.java

示例4: createContainerPaymentMethod

import org.json.JSONObject; //導入方法依賴的package包/類
static PaymentMethod createContainerPaymentMethod(final JSONObject paymentMethodJSON, final String logoUrl)
        throws JSONException {
    final PaymentMethod paymentMethod = new PaymentMethod();

    final JSONObject group = paymentMethodJSON.getJSONObject("group");
    paymentMethod.type = group.getString("type");
    paymentMethod.name = group.getString("name");
    paymentMethod.logoUrl = logoUrl + group.getString("type") + ".png";
    paymentMethod.paymentMethodData = group.getString("paymentMethodData");

    final JSONArray inputDetails = paymentMethodJSON.optJSONArray("inputDetails");
    if (inputDetails != null) {
        paymentMethod.inputDetails = parseInputDetails(inputDetails);
    }

    return paymentMethod;
}
 
開發者ID:Adyen,項目名稱:adyen-android,代碼行數:18,代碼來源:PaymentMethod.java

示例5: getCollationHit

import org.json.JSONObject; //導入方法依賴的package包/類
private long getCollationHit(JSONObject resultJson) throws JSONException
{
    JSONObject spellcheck = resultJson.getJSONObject("spellcheck");
    JSONArray suggestions = spellcheck.getJSONArray("suggestions");

    for (int key = 0, value = 1, length = suggestions.length(); value < length; key += 2, value += 2)
    {
        String jsonName = suggestions.getString(key);

        if ("collation".equals(jsonName))
        {
            JSONObject valueJsonObject = suggestions.getJSONObject(value);
            long collationHit = valueJsonObject.getLong("hits");
            return collationHit;
        }
    }

    return 0;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:20,代碼來源:SpellCheckDecisionManagerTest.java

示例6: DownloadArticle

import org.json.JSONObject; //導入方法依賴的package包/類
public Article DownloadArticle(String articleID) throws Exception {
    String articleResult = GetParam(downloadArticleURL + articleID, null);
    System.out.println(articleResult);
    JSONObject articleObject = new JSONObject(articleResult);
    JSONObject articleDetail = articleObject.getJSONObject("msg");
    Article article = new Article(articleDetail);
    System.out.println(article);
    return article;
}
 
開發者ID:zackszhu,項目名稱:hack_sjtu_2017,代碼行數:10,代碼來源:HttpHandler.java

示例7: action

import org.json.JSONObject; //導入方法依賴的package包/類
public void action(final Event<JSONObject> event) throws EventException {
	final JSONObject data = event.getData();

	logger.debug("Processing an event[type={}, data={}] in listener[className={}]", event.getType(), data,
			RhythmArticleSender.class);
	try {
		final JSONObject originalArticle = data.getJSONObject(Article.ARTICLE);

		if (!originalArticle.getBoolean(Article.ARTICLE_IS_PUBLISHED)) {
			logger.debug("Ignores post article[title={}] to Rhythm",
					originalArticle.getString(Article.ARTICLE_TITLE));

			return;
		}

		final JSONObject preference = preferenceQueryService.getPreference();

		if (null == preference) {
			throw new EventException("Not found preference");
		}

		if (!StringUtils.isBlank(originalArticle.optString(Article.ARTICLE_VIEW_PWD))) {
			return;
		}

		if (Latkes.getServePath().contains("localhost")) {
			logger.info("Solo runs on local server, so should not send this article[id={}, title={}] to Rhythm",
					originalArticle.getString(Keys.OBJECT_ID), originalArticle.getString(Article.ARTICLE_TITLE));
			return;
		}

		final HTTPRequest httpRequest = new HTTPRequest();

		httpRequest.setURL(ADD_ARTICLE_URL);
		httpRequest.setRequestMethod(RequestMethod.POST);
		final JSONObject requestJSONObject = new JSONObject();
		final JSONObject article = new JSONObject();

		article.put(Keys.OBJECT_ID, originalArticle.getString(Keys.OBJECT_ID));
		article.put(Article.ARTICLE_TITLE, originalArticle.getString(Article.ARTICLE_TITLE));
		article.put(Article.ARTICLE_PERMALINK, originalArticle.getString(Article.ARTICLE_PERMALINK));
		article.put(Article.ARTICLE_TAGS_REF, originalArticle.getString(Article.ARTICLE_TAGS_REF));
		article.put(Article.ARTICLE_AUTHOR_EMAIL, originalArticle.getString(Article.ARTICLE_AUTHOR_EMAIL));
		article.put(Article.ARTICLE_CONTENT, originalArticle.getString(Article.ARTICLE_CONTENT));
		article.put(Article.ARTICLE_CREATE_DATE,
				((Date) originalArticle.get(Article.ARTICLE_CREATE_DATE)).getTime());
		article.put(Common.POST_TO_COMMUNITY, originalArticle.getBoolean(Common.POST_TO_COMMUNITY));

		// Removes this property avoid to persist
		originalArticle.remove(Common.POST_TO_COMMUNITY);

		requestJSONObject.put(Article.ARTICLE, article);
		requestJSONObject.put(Common.BLOG_VERSION, SoloConstant.VERSION);
		requestJSONObject.put(Common.BLOG, "B3log Solo");
		requestJSONObject.put(Option.ID_C_BLOG_TITLE, preference.getString(Option.ID_C_BLOG_TITLE));
		requestJSONObject.put("blogHost", Latkes.getServePath());
		requestJSONObject.put("userB3Key", preference.optString(Option.ID_C_KEY_OF_SOLO));
		requestJSONObject.put("clientAdminEmail", preference.optString(Option.ID_C_ADMIN_EMAIL));
		requestJSONObject.put("clientRuntimeEnv", Latkes.getRuntimeEnv().name());

		httpRequest.setPayload(requestJSONObject.toString().getBytes("UTF-8"));

		urlFetchService.fetchAsync(httpRequest);
	} catch (final Exception e) {
		logger.error("Sends an article to Rhythm error: {}", e.getMessage());
	}

	logger.debug("Sent an article to Rhythm");
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:70,代碼來源:RhythmArticleSender.java

示例8: checkRuleComplete

import org.json.JSONObject; //導入方法依賴的package包/類
private void checkRuleComplete(JSONObject result) throws Exception
{
    assertNotNull("Response is null.", result);

    // if id present in response -> rule was created
    assertTrue(result.has("id"));

    assertEquals(result.getString("title"), "test_rule");
    assertEquals(result.getString("description"), "this is description for test_rule");

    JSONArray ruleType = result.getJSONArray("ruleType");

    assertEquals(1, ruleType.length());
    assertEquals("outbound", ruleType.getString(0));

    assertTrue(result.getBoolean("applyToChildren"));
    assertFalse(result.getBoolean("executeAsynchronously"));
    assertFalse(result.getBoolean("disabled"));
    assertTrue(result.has("owningNode"));
    JSONObject owningNode = result.getJSONObject("owningNode");
    assertTrue(owningNode.has("nodeRef"));
    assertTrue(owningNode.has("name"));
    assertTrue(result.has("url"));

    JSONObject jsonAction = result.getJSONObject("action");

    assertTrue(jsonAction.has("id"));

    assertEquals(jsonAction.getString("actionDefinitionName"), "composite-action");
    assertEquals(jsonAction.getString("description"), "this is description for composite-action");
    assertEquals(jsonAction.getString("title"), "test_title");

    assertTrue(jsonAction.getBoolean("executeAsync"));

    assertTrue(jsonAction.has("actions"));
    assertTrue(jsonAction.has("conditions"));
    assertTrue(jsonAction.has("compensatingAction"));
    assertTrue(jsonAction.has("url"));
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:40,代碼來源:RuleServiceTest.java

示例9: parseJSON

import org.json.JSONObject; //導入方法依賴的package包/類
private void parseJSON(String data) throws JSONException {
    if (data == null)
        return;

    Route route = null;
    List<Route> routes = new ArrayList<>();
    JSONObject jsonData = new JSONObject(data);
    JSONArray jsonRoutes = jsonData.getJSONArray("routes");
    for (int i = 0; i < jsonRoutes.length(); i++) {
        JSONObject jsonRoute = jsonRoutes.getJSONObject(i);
        route = new Route();

        JSONObject overview_polylineJson = jsonRoute.getJSONObject("overview_polyline");
        JSONArray jsonLegs = jsonRoute.getJSONArray("legs");
        JSONObject jsonLeg = jsonLegs.getJSONObject(0);
        JSONObject jsonDistance = jsonLeg.getJSONObject("distance");
        JSONObject jsonDuration = jsonLeg.getJSONObject("duration");
        JSONObject jsonEndLocation = jsonLeg.getJSONObject("end_location");
        JSONObject jsonStartLocation = jsonLeg.getJSONObject("start_location");

        route.setDistance(new Distance(jsonDistance.getString("text"), jsonDistance.getInt("value")));
        route.setDuration(new Duration(jsonDuration.getString("text"), jsonDuration.getInt("value")));
        route.setEndAddress(jsonLeg.getString("end_address"));
        route.setStartAddress(jsonLeg.getString("start_address"));
        route.setStartLocation(new LatLng(jsonStartLocation.getDouble("lat"), jsonStartLocation.getDouble("lng")));
        route.setEndLocation(new LatLng(jsonEndLocation.getDouble("lat"), jsonEndLocation.getDouble("lng")));
        route.setPoints(decodePolyLine(overview_polylineJson.getString("points")));

        routes.add(route);
    }

    listener.onDirectionFinderSuccess(routes, route);
}
 
開發者ID:Balthair94,項目名稱:AppGoogleMaps,代碼行數:34,代碼來源:DownloadRawData.java

示例10: RemoteNodeData

import org.json.JSONObject; //導入方法依賴的package包/類
/**
 * the constructor.
 *
 * @param config
 *            the configuration to use.
 */
public RemoteNodeData(final JSONObject config) {
	final JSONObject timersJson = config.getJSONObject(ConfigurationUtil.TIMERS);
	timersMap = TimerUtil.getTimerMap(timersJson);
	sleepIntervalMs = JsonUtil.getTime(config, ConfigurationUtil.SLEEP_INTERVAL);
	recycleIntervalMs = JsonUtil.getTime(config, ConfigurationUtil.RECYCLE_INTERVAL);
}
 
開發者ID:coranos,項目名稱:neo-java,代碼行數:13,代碼來源:RemoteNodeData.java

示例11: doInBackground

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
protected Integer doInBackground(Context... params) {

    HttpResponse response;
    try {
        LocationManager lm = (LocationManager) params[0].getSystemService(Context.LOCATION_SERVICE);
        Criteria crit = new Criteria();
        crit.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = lm.getBestProvider(crit, true);

        Location loc = lm.getLastKnownLocation(provider);

        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();

        request.setURI(new URI(Utils.WEATHER_URL + "lat=" +
                loc.getLatitude() +
                "&lon=" +
                +loc.getLongitude()
                + "&units=metric"));

        response = client.execute(request);
        String result = EntityUtils.toString(response.getEntity());
        JSONObject jsonResponse = new JSONObject(result);
        JSONObject jsonWeather = jsonResponse.getJSONObject("main");
        return jsonWeather.getInt("temp");

    } catch (Exception e) {
        error = e;
    }
    return 0;
}
 
開發者ID:feup-infolab,項目名稱:labtablet,代碼行數:33,代碼來源:AsyncWeatherFetcher.java

示例12: process

import org.json.JSONObject; //導入方法依賴的package包/類
@Override
public void process(JSONObject content, JSONObject rawRequest, Server server) {
    JSONObject user = content.getJSONObject("user");
    GroupUser gUser = server.getGroupUserById(user.getString("id"));
    server.getConnectedClients().remove(gUser);
    api.getEventManager().executeEvent(new UserBannedEvent(server, gUser));
}
 
開發者ID:discord-java,項目名稱:discord.jar,代碼行數:8,代碼來源:BanPoll.java

示例13: a

import org.json.JSONObject; //導入方法依賴的package包/類
private void a(String str) {
    String str2;
    try {
        JSONObject jSONObject = new JSONObject(str);
        String string = jSONObject.getString("clientId");
        try {
            if (!TextUtils.isEmpty(string)) {
                JSONObject jSONObject2 = jSONObject.getJSONObject("param");
                if (jSONObject2 instanceof JSONObject) {
                    jSONObject2 = jSONObject2;
                } else {
                    jSONObject2 = null;
                }
                String string2 = jSONObject.getString(a.g);
                String string3 = jSONObject.getString(a.d);
                a aVar = new a("call");
                aVar.j = string3;
                aVar.k = string2;
                aVar.m = jSONObject2;
                aVar.i = string;
                a(aVar);
            }
        } catch (Exception e) {
            str2 = string;
            if (!TextUtils.isEmpty(str2)) {
                try {
                    a(str2, a.RUNTIME_ERROR);
                } catch (JSONException e2) {
                }
            }
        }
    } catch (Exception e3) {
        str2 = null;
        if (!TextUtils.isEmpty(str2)) {
            a(str2, a.RUNTIME_ERROR);
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:39,代碼來源:d.java

示例14: getGeocodeResults

import org.json.JSONObject; //導入方法依賴的package包/類
private GeocodingResult[] getGeocodeResults(String respContent, SearchBoundary boundary)
{
	JSONObject features = new JSONObject(respContent);
	JSONArray arr = (JSONArray)features.get("features");

	GeocodingResult[] results = new GeocodingResult[arr.length()];
	
	for (int j = 0; j < arr.length(); j++) {
		JSONObject feature = arr.getJSONObject(j);
		JSONObject geomObj = feature.getJSONObject("geometry");
		JSONArray coordsObj = geomObj.getJSONArray("coordinates");
		
		double lon = Double.parseDouble(coordsObj.get(0).toString());
		double lat = Double.parseDouble(coordsObj.get(1).toString());
		
		if (boundary != null && !boundary.contains(lon, lat))
			continue;		

		JSONObject props = feature.getJSONObject("properties");

		String country = props.optString("country");
		String state = props.optString("state");
		String postal_code = props.optString("postcode");
		String locality = props.optString("city");
		String street = props.optString("street");
		String house_number = props.optString("housenumber");
		String name = props.optString("name");
		String house = name;
		String osm_value = props.optString("osm_value");
		if (!Helper.isEmpty(osm_value))
		{
			String osm_key = props.optString("osm_key");
			if (osm_value.equals("district"))
			{
				//state_district = osm_key;
			}
			else if (osm_value.equals("state") && osm_key.equals("place"))
				state = name;
		}

		if (state != null || locality != null || street != null) {
			GeocodingResult gr = new GeocodingResult();
			gr.locality = locality;
			gr.country = country;
			gr.region = state;
			//gr.stateDistrict = state_district;
			gr.postalCode = postal_code;
			gr.street = street;
			gr.name = house;
			gr.houseNumber = house_number;
			gr.longitude = lon;
			gr.latitude = lat;
			
			results[j] = gr;
		}
	}
	
	Arrays.sort(results, new GeocodingResultComparator());
	
	return results;
}
 
開發者ID:GIScience,項目名稱:openrouteservice,代碼行數:62,代碼來源:PhotonGeocoder.java

示例15: Annotation

import org.json.JSONObject; //導入方法依賴的package包/類
public Annotation(JSONObject obj) throws JSONException {
    timestamp = obj.getLong("1");
    JSONObject info = obj.getJSONObject("2");
    desc = info.getString("3");
    type = Type.parse(info.getInt("4"));
}
 
開發者ID:devgianlu,項目名稱:PlayConsoleAndroidAPI,代碼行數:7,代碼來源:Annotation.java


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