当前位置: 首页>>代码示例>>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;未经允许,请勿转载。