本文整理匯總了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 + "";
}
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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");
}
示例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"));
}
示例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);
}
示例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);
}
示例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;
}
示例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));
}
示例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);
}
}
}
示例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;
}
示例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"));
}