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