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


Java JSONArray.length方法代碼示例

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


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

示例1: postDecodeTracks

import org.json.JSONArray; //導入方法依賴的package包/類
@PostMapping(value = "/decodetracks", consumes = "application/json", produces = "application/json")
@ResponseBody
public String postDecodeTracks(HttpServletRequest request, HttpServletResponse response, @RequestBody String body) throws IOException {
    log(request);

    if (!isAuthorized(request, response))
        return "";

    JSONArray requestJSON = new JSONArray(body);
    JSONArray responseJSON = new JSONArray();

    for (int i = 0; i < requestJSON.length(); i++) {
        String track = requestJSON.getString(i);
        AudioTrack audioTrack = Util.toAudioTrack(track);

        JSONObject infoJSON = trackToJSON(audioTrack);
        JSONObject trackJSON = new JSONObject()
                .put("track", track)
                .put("info", infoJSON);

        responseJSON.put(trackJSON);
    }

    return responseJSON.toString();
}
 
開發者ID:Frederikam,項目名稱:Lavalink,代碼行數:26,代碼來源:AudioLoaderRestHandler.java

示例2: forwardAggregate

import org.json.JSONArray; //導入方法依賴的package包/類
public void forwardAggregate(String subreddit) {
    JSONArray result;
    if (lastFullname == null)
        result = redditConsumer.fetchInitialComment(subreddit);
    else
        result = redditConsumer.fetchForward(lastFullname);

    String tmpLastFullname = ModelsUtils.extractLastFullname(result);

    if (tmpLastFullname == null || tmpLastFullname == "")
        return;

    lastFullname = tmpLastFullname;
    for (int i = 0; i<= result.length() - 1 ; i++) {
        queueService.enqueueComment(result.getJSONObject(i));
    }
}
 
開發者ID:nicolasmanic,項目名稱:JRockets,代碼行數:18,代碼來源:CommentAggregator.java

示例3: generateEntities

import org.json.JSONArray; //導入方法依賴的package包/類
public void generateEntities() {
  JSONObject jsonImportObject = new JSONObject(this.jsonString);
  JSONArray challenges = jsonImportObject.getJSONArray("challenges");

  for (int i = 0; i < challenges.length(); i++) {
    JSONObject challengeObject = challenges.getJSONObject(i);
    Challenge challenge = new Challenge(challengeObject.getString("name"),
        users.get(challengeObject.getString("author")),
        challengeObject.getString("desc"));
    challenge.setType(ChallengeType.valueOf(challengeObject.getString("type").toUpperCase()));
    challenge.setRealm(Realm.valueOf(challengeObject.getString("realm").toUpperCase()));
    challenge.setLevel(challengeObject.getInt("level"));
    JSONArray tasks = challengeObject.getJSONArray("tasks");
    this.challenges.put(challengeObject.getString("name"), challenge);
    for (int j = 0; j < tasks.length(); j++) {
      generateChallengeContent(tasks, j, challengeObject, challenge);
    }
  }
  this.createDummyInstances(jsonImportObject.getJSONArray("dummyimplementations"));

}
 
開發者ID:tdd-pingis,項目名稱:tdd-pingpong,代碼行數:22,代碼來源:DataImporter.java

示例4: handleCityResponse

import org.json.JSONArray; //導入方法依賴的package包/類
/**
 * information of cities ;
 * @param response
 * @param provinceId
 * @return
 */
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:EdisonGu1997,項目名稱:GCWeather,代碼行數:26,代碼來源:Utility.java

示例5: addArchives

import org.json.JSONArray; //導入方法依賴的package包/類
/**
 * Adds archives (archive-articles) into the specified sitemap.
 * 
 * @param sitemap
 *            the specified sitemap
 * @throws Exception
 *             exception
 */
private void addArchives(final Sitemap sitemap) throws Exception {
	final JSONObject result = archiveDateDao.get(new Query());
	final JSONArray archiveDates = result.getJSONArray(Keys.RESULTS);

	for (int i = 0; i < archiveDates.length(); i++) {
		final JSONObject archiveDate = archiveDates.getJSONObject(i);
		final long time = archiveDate.getLong(ArchiveDate.ARCHIVE_TIME);
		final String dateString = DateFormatUtils.format(time, "yyyy/MM");

		final URL url = new URL();

		url.setLoc(Latkes.getServePath() + "/archives/" + dateString);

		sitemap.addURL(url);
	}
}
 
開發者ID:daima,項目名稱:solo-spring,代碼行數:25,代碼來源:SitemapProcessor.java

示例6: parseApiResult

import org.json.JSONArray; //導入方法依賴的package包/類
private ArrayList<Product> parseApiResult(String res) {
    ArrayList<Product> result = new ArrayList<Product>();
    try {
        JSONObject json = new JSONObject(res);
        JSONArray array = json.getJSONArray("products");
        for (int i = 0; i < array.length(); i++) {
            JSONObject productObj = (JSONObject)array.get(i);
            Product product = new Product(
                    productObj.getString("name"),
                    productObj.getString("description"),
                    productObj.getInt("id"),
                    productObj.getString("imageUrl")
            );
            result.add(product);
        }
    } catch (JSONException e) {
        Log.e("Error parsing JSON", e.getMessage());
    }
    return result;
}
 
開發者ID:aarongreenwald,項目名稱:startech-course,代碼行數:21,代碼來源:Api.java

示例7: parseAfterschoolListJSON

import org.json.JSONArray; //導入方法依賴的package包/類
public static List<Afterschool> parseAfterschoolListJSON(JSONObject rootJSONObject)
        throws JSONException {

    List<Afterschool> afterschoolList = new ArrayList<>();

    JSONArray resultJSONArray = rootJSONObject.getJSONArray("result");

    for (int index = resultJSONArray.length(); index >= 0; index++) {
        JSONObject afterschoolJSONObject = resultJSONArray.getJSONObject(index);

        int no = afterschoolJSONObject.getInt("no");
        String title = afterschoolJSONObject.getString("title");
        int target = afterschoolJSONObject.getInt("target");
        String place = afterschoolJSONObject.getString("place");
        boolean onMonday = afterschoolJSONObject.getBoolean("on_monday");
        boolean onTuesday = afterschoolJSONObject.getBoolean("on_tuesday");
        boolean onWednesday = afterschoolJSONObject.getBoolean("on_wednesday");
        boolean onSaturday = afterschoolJSONObject.getBoolean("on_saturday");
        String instructor = afterschoolJSONObject.getString("instructor");

        afterschoolList.add(new Afterschool(no, title, target, place,
                onMonday, onTuesday, onWednesday, onSaturday, instructor));
    }

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

示例8: mockPersons

import org.json.JSONArray; //導入方法依賴的package包/類
private void mockPersons() throws IOException {
  logger.warn("Deleting all persons in DB");
  personRepo.deleteAll();

  JSONArray persons = readMockFileToJsonArray(personsPath);
  for (int i = 0; i < persons.length(); i++) {
    JSONObject personJson = persons.getJSONObject(i);
    User user = new User(personJson.getString("id"));
    user.setRole(Role.valueOf(personJson.getString("role")));

    JSONArray skills = personJson.getJSONArray("skills");
    for (int j = 0; j < skills.length(); j++) {
      JSONObject skillJson = skills.getJSONObject(j);
      user.addUpdateSkill(
        skillJson.getString("name"),
        skillJson.getInt("skillLevel"),
        skillJson.getInt("willLevel"),
        false,
        false
      );
    }

    logger.info("Inserting user " + user.getId());
    personRepo.save(user);
  }
}
 
開發者ID:sinnerschrader,項目名稱:SkillWill,代碼行數:27,代碼來源:MockData.java

示例9: parse

import org.json.JSONArray; //導入方法依賴的package包/類
public static Card parse(JSONObject obj) {
    if (obj == null) {
        return null;
    }
    Card card = new Card();
    card.card_type = obj.optInt("card_type", 0);
    card.show_type = obj.optInt("show_type", 0);

    JSONArray cardGroups = obj.optJSONArray("card_group");
    if (cardGroups != null && cardGroups.length() > 0) {
        card.card_group = new ArrayList<>(cardGroups.length());
        for (int i = 0; i < cardGroups.length(); i++) {
            CardGroup cardGroup = CardGroup.parse(cardGroups.optJSONObject(i));
            if (cardGroup != null) {
                card.card_group.add(cardGroup);
            }
        }
    }
    card.openurl = obj.optString("openurl", "");

    card.mblog = MBlog.parse(obj.optJSONObject("mblog"));
    return card;
}
 
開發者ID:liying2008,項目名稱:Simpler,代碼行數:24,代碼來源:Card.java

示例10: getAppBeanMap

import org.json.JSONArray; //導入方法依賴的package包/類
private static Map<String, List<AppBean>> getAppBeanMap(JSONObject json) {
    Map<String, List<AppBean>> appBeanMap = new HashMap<>();
    try {
        JSONArray data = json.getJSONArray("layoutData");
        for (int i = 0; i < data.length(); i++) {
            if (i == 4 || i == 6 || i == 8 || i == 10 | i == 12) {
                String type = data.getJSONObject(i - 1).getJSONArray("dataList").getJSONObject(0).getString("name");
                JSONArray appArray = data.getJSONObject(i).getJSONArray("dataList");
                List<AppBean> appBeanList = new ArrayList<>();
                for (int m = 0; m < appArray.length(); m++) {
                    JSONObject jsonObject = appArray.getJSONObject(m);
                    AppBean appBean = parseAppBean(jsonObject.toString());
                    appBeanList.add(appBean);
                }
                appBeanMap.put(type, appBeanList);
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return appBeanMap;
}
 
開發者ID:guzhigang001,項目名稱:Bailan,代碼行數:24,代碼來源:JsonParseUtils.java

示例11: parseJson

import org.json.JSONArray; //導入方法依賴的package包/類
private void parseJson(String t) {
    if (mGirlDataList.size() != 0) {
        mGirlDataList.clear();
        mUrlList.clear();
    }
    try {
        JSONObject jsonObject = new JSONObject(t);
        JSONArray result = jsonObject.getJSONArray("results");
        for (int i = 0; i < result.length(); i++) {
            GirlData girl = new GirlData();
            JSONObject json = (JSONObject) result.get(i);
            String url = json.getString("url");
            if (url == null) {
                continue;
            }
            girl.setImgUrl(url);
            mUrlList.add(url);
            mGirlDataList.add(girl);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
開發者ID:Hultron,項目名稱:LifeHelper,代碼行數:24,代碼來源:GirlsFragment.java

示例12: FieldsConfig

import org.json.JSONArray; //導入方法依賴的package包/類
public FieldsConfig(JSONArray jsonFields) throws JSONException {
  this();
  if (jsonFields == null) {
    throw new JSONException("Illegal argument");
  }
  for (int i = 0; i < jsonFields.length(); i++) {
    Field f = new Field(jsonFields.getJSONObject(i));
    fields.put(f.getId(), f);
    ordering.add(f.getId());
  }
}
 
開發者ID:logistimo,項目名稱:logistimo-web-service,代碼行數:12,代碼來源:FieldsConfig.java

示例13: toList

import org.json.JSONArray; //導入方法依賴的package包/類
public static <T> List<T> toList(JSONArray array, Class<T> listClass) {
	if(array == null) {
		return null;
	}

	List<T> list = new ArrayList<>();
	for(int i = 0; i < array.length(); i++) {
		if(listClass.isInstance(array.get(i))) {
			list.add(listClass.cast(array.get(i)));
		} else {
			throw new IllegalArgumentException(String.format("Array's elements cannot be casted to %s.", listClass.getSimpleName()));
		}
	}
	return list;
}
 
開發者ID:Shadorc,項目名稱:Shadbot,代碼行數:16,代碼來源:Utils.java

示例14: validate

import org.json.JSONArray; //導入方法依賴的package包/類
@Override
public Result validate(JSONArray jsonArray, StringProperty property, String path) throws ValidationException {
    Result result = new Result();
    StringValidator validator = getValidator(property);
    for (int i = 0; i < jsonArray.length(); i++) {
        result.also(validator.validate(jsonArray.getString(i), path + "[" + i + "]"));
    }
    return result;
}
 
開發者ID:limberest,項目名稱:limberest,代碼行數:10,代碼來源:StringPropertyValidator.java

示例15: fetchAllLiveStreams

import org.json.JSONArray; //導入方法依賴的package包/類
/**
 * Returns a list of all followed currently live streams for the user with specific oauth token.
 * This should not be used for time critical tasks.
 * @param context
 * @param oauthToken
 * @return list of all currently live followed streams
 */
public static List<StreamInfo> fetchAllLiveStreams(Context context, String oauthToken) {
    final String BASE_URL = "https://api.twitch.tv/kraken/streams/followed?oauth_token=" + oauthToken + "&limit=100&offset=%s&stream_type=live";

    List<StreamInfo> mResultList = new ArrayList<>();
    try {
        boolean endReached = false;
        while (!endReached) {
            final String ARRAY_KEY = "streams";
            final String TOTAL_STREAMS_INT = "_total";

            String jsonString = Service.urlToJSONString(String.format(Locale.ROOT, BASE_URL, mResultList.size()));
            JSONObject fullDataObject = new JSONObject(jsonString);
            JSONArray streamsArray = fullDataObject.getJSONArray(ARRAY_KEY);

            int totalElements = fullDataObject.getInt(TOTAL_STREAMS_INT);
            endReached = totalElements == mResultList.size() || streamsArray.length() == 0;

            for (int i = 0; i < streamsArray.length(); i++) {
                JSONObject streamObject = streamsArray.getJSONObject(i);
                mResultList.add(JSONService.getStreamInfo(context, streamObject, null, false));
            }
        }
    } catch (JSONException | MalformedURLException ex) {
        ex.printStackTrace();
    }

    return mResultList;
}
 
開發者ID:SebastianRask,項目名稱:Pocket-Plays-for-Twitch,代碼行數:36,代碼來源:StreamsService.java


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