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


Java JSONArray.getJSONObject方法代碼示例

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


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

示例1: parseIatResult

import org.json.JSONArray; //導入方法依賴的package包/類
public static String parseIatResult(String json) {
		StringBuffer ret = new StringBuffer();
		try {
			JSONTokener tokener = new JSONTokener(json);
			JSONObject joResult = new JSONObject(tokener);

			JSONArray words = joResult.getJSONArray("ws");
			for (int i = 0; i < words.length(); i++) {
				// 轉寫結果詞,默認使用第一個結果
				JSONArray items = words.getJSONObject(i).getJSONArray("cw");
				JSONObject obj = items.getJSONObject(0);
				ret.append(obj.getString("w"));
//				如果需要多候選結果,解析數組其他字段
//				for(int j = 0; j < items.length(); j++)
//				{
//					JSONObject obj = items.getJSONObject(j);
//					ret.append(obj.getString("w"));
//				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
		return ret.toString();
	}
 
開發者ID:iPanelkegy,項目名稱:MobileMedia,代碼行數:25,代碼來源:JsonParser.java

示例2: handleCityResponse

import org.json.JSONArray; //導入方法依賴的package包/類
/**
 * 解析和處理服務器返回的市級數據
 */
public static boolean handleCityResponse(String response, int provinceId) {
    if (!TextUtils.isEmpty(response)) {
        try {
            JSONArray allCities = new JSONArray(response);
            for (int i = 0; i < allCities.length(); i++) {
                JSONObject cityObject = allCities.getJSONObject(i);
                City city = new City();
                city.setCityName(cityObject.getString("name"));
                city.setCityCode(cityObject.getInt("id"));
                city.setProvinceId(provinceId);
                city.save();
            }
            return true;
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return false;
}
 
開發者ID:Shmilyz,項目名稱:Swap,代碼行數:23,代碼來源:Utility.java

示例3: handleCityResponse

import org.json.JSONArray; //導入方法依賴的package包/類
public static boolean handleCityResponse(String response, int provinceId) {
    if (!TextUtils.isEmpty(response)) {
        try {
            JSONArray jsonArray = new JSONArray(response);
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                City city = new City();
                city.setId(jsonObject.getInt("id"));
                city.setCityName(jsonObject.getString("name"));
                city.setProvinceId(provinceId);
                city.save();
            }
            return true;
        } catch (JSONException e) {
            e.printStackTrace();
            return false;
        }
    }
    return false;
}
 
開發者ID:xuqiang0930,項目名稱:xqWeather,代碼行數:21,代碼來源:Utility.java

示例4: getGuildInvites

import org.json.JSONArray; //導入方法依賴的package包/類
@Override
public List<IInvite> getGuildInvites() {
    if (!guild.getSelfMember().hasPermissions(true, Permission.MANAGE_SERVER)) {
        throw new PermissionException(Permission.ADMINISTRATOR, Permission.MANAGE_SERVER);
    }

    List<IInvite> invites = new ArrayList<>();
    ObjectBuilder builder = new ObjectBuilder((IdentityImpl) getIdentity());
    JSONArray guildInvites = new Requester(getIdentity(), HttpPath.Invite.GET_GUILD_INVITES).request(guild.getId())
            .getAsJSONArray();

    for (int i = 0; i < guildInvites.length(); i++) {
        JSONObject invite = guildInvites.getJSONObject(i);
        invites.add(builder.buildInvite(invite));
    }

    return invites;
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:19,代碼來源:InviteManager.java

示例5: setupFeeds

import org.json.JSONArray; //導入方法依賴的package包/類
private void setupFeeds(JSONArray jsonAll) throws Exception {
    ArrayList<GoalFeed> goalFeedList = new ArrayList<>();

    for (int i = 0; i < jsonAll.length(); i++) {
        JSONObject jsonObj = jsonAll.getJSONObject(i);
        String guid = jsonObj.getString("guid");
        String createdUsername = jsonObj.getString("createdUsername");
        long wager = jsonObj.getLong("wager");
        long upvoteCount = jsonObj.getLong("upvoteCount");

        int goalCompleteResultInt = jsonObj.getInt("goalCompleteResult");
        Goal.GoalCompleteResult goalCompleteResult = Goal.GoalCompleteResult.None;
        if (goalCompleteResultInt < Goal.GoalCompleteResult.values().length)
            goalCompleteResult = Goal.GoalCompleteResult.values()[goalCompleteResultInt];

        GoalFeed goalFeed = new GoalFeed(guid, wager, createdUsername, upvoteCount, goalCompleteResult);
        goalFeedList.add(goalFeed);
    }

    GoalHelper.getInstance().setFeeds(goalFeedList);
}
 
開發者ID:Q115,項目名稱:Goalie_Android,代碼行數:22,代碼來源:RESTSync.java

示例6: removeTestIfPresent

import org.json.JSONArray; //導入方法依賴的package包/類
private void removeTestIfPresent(JSONObject issue) {
    JSONArray tests = issue.getJSONArray("tests");
    for (int i = 0; i < tests.length(); i++) {
        JSONObject testObj = tests.getJSONObject(i);
        String name = testObj.getString("path");
        if (name.equals(path)) {
            tests.remove(i);
        }
    }
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:11,代碼來源:TestPropertiesInfo.java

示例7: getParentOf

import org.json.JSONArray; //導入方法依賴的package包/類
@Override
public JSONObject getParentOf(String id, String parentType) throws JSONException, IOException, HttpException {
	JSONObject json = client.getJson("/suite-api/api/resources/" + id + "/relationships", "relationshipType=PARENT");
	JSONArray rl = json.getJSONArray("resourceList");
	for(int i = 0; i < rl.length(); ++i) {
		JSONObject r = rl.getJSONObject(i);
		
		// If there's more than one we only return the first one.
		//
		if(r.getJSONObject("resourceKey").getString("resourceKindKey").equals(parentType))
			return r;
	}
	return null;
}
 
開發者ID:prydin,項目名稱:vrops-export,代碼行數:15,代碼來源:Exporter.java

示例8: getTaskStatistics

import org.json.JSONArray; //導入方法依賴的package包/類
public static JSONObject getTaskStatistics(String taskName, String host) throws IOException {
    String resp = OKHttpUtil.getInstance().doGet("http://" + host + ":5051/monitor/statistics.json", null,null);
    JSONArray array = new JSONArray(resp);
    for (int i = 0; i < array.length(); i++) {
        JSONObject jsonObj = array.getJSONObject(i);
        String executorId = jsonObj.getString("executor_id");
        if (executorId.equals(taskName)) {
            return jsonObj.getJSONObject("statistics");
        }
    }
    return null;
}
 
開發者ID:huang-kai,項目名稱:auto-scale-java,代碼行數:13,代碼來源:MesosUtil.java

示例9: buildInfoAsMap

import org.json.JSONArray; //導入方法依賴的package包/類
private static Map<String, JSONObject> buildInfoAsMap(JSONArray buildInfos) throws JSONException {
  Map<String, JSONObject> result = new HashMap<String, JSONObject>();
  for (int i = 0; i < buildInfos.length(); i++) {
    JSONObject componentBuildInfo = buildInfos.getJSONObject(i);
    result.put(componentBuildInfo.getString("type"), componentBuildInfo);
  }
  return result;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:9,代碼來源:ExternalComponentGenerator.java

示例10: removeAndGetTest

import org.json.JSONArray; //導入方法依賴的package包/類
private JSONObject removeAndGetTest(String section) {
    JSONArray history = TestRunnerHistory.getInstance().getHistory(section);
    for (int i = 0; i < history.length(); i++) {
        JSONObject test = history.getJSONObject(i);
        JSONObject selectedItem = historyView.getSelectionModel().getSelectedItem();
        if (test.getString("name").equals(selectedItem.getString("name"))) {
            historyView.getItems().remove(historyView.getSelectionModel().getSelectedItem());
            history.remove(i);
            return test;
        }
    }
    return null;
}
 
開發者ID:jalian-systems,項目名稱:marathonv5,代碼行數:14,代碼來源:FavouriteHistoryStage.java

示例11: testGetMemberships

import org.json.JSONArray; //導入方法依賴的package包/類
public void testGetMemberships() throws Exception
{
    // Create a site
    String shortName  = GUID.generate();
    createSite("myPreset", shortName, "myTitle", "myDescription", SiteVisibility.PUBLIC, 200);
    
    // Check the memberships
    Response response = sendRequest(new GetRequest(URL_SITES + "/" + shortName + URL_MEMBERSHIPS), 200);
    JSONArray result = new JSONArray(response.getContentAsString());        
    assertNotNull(result);
    assertEquals(1, result.length());
    JSONObject membership = result.getJSONObject(0);
    assertEquals(SiteModel.SITE_MANAGER, membership.get("role"));
    assertEquals(USER_ONE, membership.getJSONObject("authority").get("userName"));        
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:16,代碼來源:SiteServiceTest.java

示例12: getPinnedMessages

import org.json.JSONArray; //導入方法依賴的package包/類
/**
 * Get a list of all pinned messages of a channel.
 *
 * @return the list of messages, list size without limits.
 */
public List<IMessage> getPinnedMessages() {
    JSONArray pins = new Requester(identity, HttpPath.Channel.GET_PINNED_MESSAGES)
            .request(channel.getId()).getAsJSONArray();

    ObjectBuilder builder = new ObjectBuilder(identity);
    List<IMessage> pinnedMessages = new ArrayList<>();
    for (int i = 0; i < pins.length(); i++) {
        JSONObject msg = pins.getJSONObject(i);
        Message message = builder.buildMessage(msg);
        pinnedMessages.add(message);
    }
    history.cacheAll(pinnedMessages.toArray(new IMessage[pinnedMessages.size()]));
    return pinnedMessages;
}
 
開發者ID:AlienIdeology,項目名稱:J-Cord,代碼行數:20,代碼來源:MessageHistory.java

示例13: restoreTimeControlsList

import org.json.JSONArray; //導入方法依賴的package包/類
/**
 * Get the stored TimeControl list from shared preferences.
 *
 * @return TimeControl list.
 */
public static ArrayList<TimeControl> restoreTimeControlsList(Context context) {

    Log.i(TAG, "Looking for stored time controls");

    SharedPreferences sp = getSharedPreferences(context);
    String jsonString = sp.getString(TIME_CONTROLS_PREF_FIELD_NAME, null);

    if (jsonString == null) {
        Log.w(TAG, "Not able to read the preference");
        return null;
    }

    ArrayList<TimeControl> timeControls = new ArrayList<TimeControl>();
    try {
        JSONObject json = new JSONObject(jsonString);
        JSONArray timeControlsJSONArray = json.getJSONArray("timecontrols");
        for (int i = 0; i < timeControlsJSONArray.length(); i++) {
            JSONObject timeControlJSON = timeControlsJSONArray.getJSONObject(i);

            JSONObject timeIncrementJSONOBject = timeControlJSON.getJSONObject("timeincrement");
            JSONArray timeControlStagesJSON = timeControlJSON.getJSONArray("stages");

            String name = timeControlJSON.getString("name");
            Stage[] stages = getStages(timeControlStagesJSON);
            TimeIncrement timeIncrement = getTimeIncrement(timeIncrementJSONOBject);

            TimeControl timeControl = new TimeControl(name, stages, timeIncrement);
            timeControls.add(timeControl);
        }

    } catch (JSONException e) {
        Log.e(TAG, e.getMessage());
        e.printStackTrace();
        return null;
    }

    Log.i(TAG, "Retrieving " + timeControls.size() + " time controls.");
    return timeControls;
}
 
開發者ID:ChessCom,項目名稱:android-chessclock,代碼行數:45,代碼來源:TimeControlParser.java

示例14: search

import org.json.JSONArray; //導入方法依賴的package包/類
private void search(JSONArray args) throws JSONException
{
    final JSONArray filter = args.getJSONArray(0);
    final JSONObject options = args.get(1) == null ? null : args.getJSONObject(1);
    this.cordova.getThreadPool().execute(new Runnable() {
        public void run() {
            JSONArray res = contactAccessor.search(filter, options);
            callbackContext.success(res);
        }
    });
}
 
開發者ID:rodrigonsh,項目名稱:alerta-fraude,代碼行數:12,代碼來源:ContactManager.java

示例15: deleteEvent

import org.json.JSONArray; //導入方法依賴的package包/類
private void deleteEvent(JSONArray args) {
  if (args.length() == 0) {
    System.err.println("Exception: No Arguments passed");
    return;
  }

  // note that if the dev didn't call requestWritePermission before calling this method and calendarPermissionGranted returns false,
  // the app will ask permission and this method needs to be invoked again (done for backward compat).
  if (!calendarPermissionGranted(Manifest.permission.WRITE_CALENDAR)) {
    requestWritePermission(PERMISSION_REQCODE_DELETE_EVENT);
    return;
  }

  try {
    final JSONObject jsonFilter = args.getJSONObject(0);

    cordova.getThreadPool().execute(new Runnable() {
      @Override
      public void run() {

        boolean deleteResult = getCalendarAccessor().deleteEvent(
                null,
                jsonFilter.optLong("startTime"),
                jsonFilter.optLong("endTime"),
                getPossibleNullString("title", jsonFilter),
                getPossibleNullString("location", jsonFilter));

        callback.sendPluginResult(new PluginResult(PluginResult.Status.OK, deleteResult));
      }
    });
  } catch (JSONException e) {
    System.err.println("Exception: " + e.getMessage());
    callback.error(e.getMessage());
  }
}
 
開發者ID:disit,項目名稱:siiMobilityAppKit,代碼行數:36,代碼來源:Calendar.java


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