本文整理汇总了Java中org.json.JSONObject.optJSONArray方法的典型用法代码示例。如果您正苦于以下问题:Java JSONObject.optJSONArray方法的具体用法?Java JSONObject.optJSONArray怎么用?Java JSONObject.optJSONArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.json.JSONObject
的用法示例。
在下文中一共展示了JSONObject.optJSONArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseResolveScanResponse
import org.json.JSONObject; //导入方法依赖的package包/类
private static Collection<PwsResult> parseResolveScanResponse(JSONObject result) {
// Get the metadata array.
Collection<PwsResult> pwsResults = new ArrayList<>();
JSONArray metadata = result.optJSONArray("results");
if (metadata == null) {
// There are no valid results.
return pwsResults;
}
// Loop through the metadata for each url.
for (int i = 0; i < metadata.length(); i++) {
try {
pwsResults.add(PwsResult.jsonDeserialize(metadata.getJSONObject(i)));
} catch (JSONException e) {
Log.e(TAG, "PWS returned invalid data", e);
continue;
}
}
return pwsResults;
}
示例2: AttestationResult
import org.json.JSONObject; //导入方法依赖的package包/类
public AttestationResult(String decodedPayload) throws JSONException {
JSONObject jo = new JSONObject(decodedPayload);
nonce = jo.optString("nonce", "");
apkDigestSha256 = jo.optString("apkDigestSha256", "");
apkPackageName = jo.optString("apkPackageName", "");
basicIntegrity = jo.optBoolean("basicIntegrity", false);
ctsProfileMatch = jo.optBoolean("ctsProfileMatch", false);
timestampMs = jo.optLong("timestampMs", 0);
extension = jo.optString("extension", "");
JSONArray ja = jo.optJSONArray("apkCertificateDigestSha256");
if (ja != null) {
String[] certDigests = new String[ja.length()];
for (int i = 0; i < ja.length(); i++) {
certDigests[i] = ja.getString(i);
}
apkCertificateDigestSha256 = certDigests;
}
}
示例3: parsePrecomps
import org.json.JSONObject; //导入方法依赖的package包/类
private static void parsePrecomps(
@Nullable JSONArray assetsJson, LottieComposition composition) {
if (assetsJson == null) {
return;
}
int length = assetsJson.length();
for (int i = 0; i < length; i++) {
JSONObject assetJson = assetsJson.optJSONObject(i);
JSONArray layersJson = assetJson.optJSONArray("layers");
if (layersJson == null) {
continue;
}
List<Layer> layers = new ArrayList<>(layersJson.length());
LongSparseArray<Layer> layerMap = new LongSparseArray<>();
for (int j = 0; j < layersJson.length(); j++) {
Layer layer = Layer.Factory.newInstance(layersJson.optJSONObject(j), composition);
layerMap.put(layer.getId(), layer);
layers.add(layer);
}
String id = assetJson.optString("id");
composition.precomps.put(id, layers);
}
}
示例4: parse
import org.json.JSONObject; //导入方法依赖的package包/类
private List<EmojiCategory> parse(String data) {
List<EmojiCategory> result = Collections.emptyList();
try {
JSONObject object = new JSONObject(data);
JSONArray array = object.optJSONArray("data");
if (array != null && array.length() > 0) {
result = new ArrayList<>();
for (int i = 0; i < array.length(); i++) {
EmojiCategory category = EmojiCategory.fromJson(array.optJSONObject(i));
if (!category.isEmpty()) {
result.add(category);
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
return result;
}
示例5: getShopList
import org.json.JSONObject; //导入方法依赖的package包/类
public static List<ShopInfo> getShopList(String result) {
List<ShopInfo> list = new ArrayList<>();
ShopInfo info;
try {
JSONObject obj = new JSONObject(result);
JSONArray infoArr = obj.optJSONArray("info");
int len = infoArr.length();
for (int i = 0; i < len; i++) {
JSONObject temp = infoArr.getJSONObject(i);
info = new ShopInfo();
info.setId(temp.optString("id"));
info.setName(temp.optString("name"));
info.setImgUrl(temp.optString("icon"));
list.add(info);
}
} catch (JSONException e) {
e.printStackTrace();
}
return list;
}
示例6: parseList
import org.json.JSONObject; //导入方法依赖的package包/类
public static LinkedList<BooheeAdvertisementBean> parseList(JSONObject object) {
JSONArray array = object.optJSONArray("advertisements");
if (array == null) {
return null;
}
return (LinkedList) new Gson().fromJson(array.toString(), new
TypeToken<LinkedList<BooheeAdvertisementBean>>() {
}.getType());
}
示例7: getLocations
import org.json.JSONObject; //导入方法依赖的package包/类
/**
* Extract created user locations from the bulk response.
* @param response
* @return
* @throws JSONException
*/
public ArrayList<String> getLocations (String response) throws JSONException {
ArrayList<String> UserLocations = new ArrayList<>();
JSONObject jsonObject = new JSONObject(response);
JSONArray jsonarray = jsonObject.optJSONArray("Operations");
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject innerJsonobject = jsonarray.getJSONObject(i);
String location = innerJsonobject.getString("location");
UserLocations.add(location);
}
return UserLocations;
}
示例8: getMostCommentArticles
import org.json.JSONObject; //导入方法依赖的package包/类
public List<JSONObject> getMostCommentArticles(final int num) throws RepositoryException {
final Query query = new Query().addSort(Article.ARTICLE_COMMENT_COUNT, SortDirection.DESCENDING)
.addSort(Article.ARTICLE_UPDATE_DATE, SortDirection.DESCENDING)
.setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true))
.setCurrentPageNum(1).setPageSize(num).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(array);
}
示例9: parseSurveyOptions
import org.json.JSONObject; //导入方法依赖的package包/类
public static SurveyOptionsModel parseSurveyOptions(String response){
SurveyOptionsModel optionsMode = new SurveyOptionsModel();
if (TextUtils.isEmpty(response)) {
return optionsMode;
}
try {
JSONObject json = new JSONObject(response);
JSONObject result = json.getJSONObject("result");
if (result.has("title")) {
optionsMode.setTitle(result.getString("title"));
}
if (result.has("desc")) {
optionsMode.setDesc(result.getString("desc"));
}
if (result.has("options")) {
List<OptionsModel> options = new ArrayList<OptionsModel>();
JSONArray optionsArray = result.optJSONArray("options");
if (optionsArray != null && optionsArray.length() > 0) {
for (int i = 0; i < optionsArray.length(); i++) {
JSONObject data = optionsArray.optJSONObject(i);
OptionsModel optionItem = new OptionsModel();
optionItem.setId(data.optString("id"));
optionItem.setText(data.getString("text"));
options.add(optionItem);
}
}
optionsMode.setOptions(options);
}
} catch (JSONException e) {
e.printStackTrace();
}
return optionsMode;
}
示例10: parseDialogConfigurations
import org.json.JSONObject; //导入方法依赖的package包/类
private static Map<String, Map<String, DialogFeatureConfig>> parseDialogConfigurations(
JSONObject dialogConfigResponse) {
HashMap<String, Map<String, DialogFeatureConfig>> dialogConfigMap = new HashMap<String, Map<String, DialogFeatureConfig>>();
if (dialogConfigResponse != null) {
JSONArray dialogConfigData = dialogConfigResponse.optJSONArray("data");
if (dialogConfigData != null) {
for (int i = 0; i < dialogConfigData.length(); i++) {
DialogFeatureConfig dialogConfig = DialogFeatureConfig.parseDialogConfig(
dialogConfigData.optJSONObject(i));
if (dialogConfig == null) {
continue;
}
String dialogName = dialogConfig.getDialogName();
Map<String, DialogFeatureConfig> featureMap = dialogConfigMap.get(dialogName);
if (featureMap == null) {
featureMap = new HashMap<String, DialogFeatureConfig>();
dialogConfigMap.put(dialogName, featureMap);
}
featureMap.put(dialogConfig.getFeatureName(), dialogConfig);
}
}
}
return dialogConfigMap;
}
示例11: parseJSONDefinition
import org.json.JSONObject; //导入方法依赖的package包/类
private static Map<Integer, Set<Integer>> parseJSONDefinition(JSONObject definition) {
JSONArray itemsArray = definition.optJSONArray("items");
if (itemsArray.length() == 0) {
return null;
}
Map<Integer, Set<Integer>> items = new HashMap<>();
for (int i = 0; i < itemsArray.length(); i++) {
JSONObject item = itemsArray.optJSONObject(i);
if (item == null) {
continue;
}
int code = item.optInt("code");
if (code == 0) {
continue;
}
Set<Integer> subcodes = null;
JSONArray subcodesArray = item.optJSONArray("subcodes");
if (subcodesArray != null && subcodesArray.length() > 0) {
subcodes = new HashSet<>();
for (int j = 0; j < subcodesArray.length(); j++) {
int subCode = subcodesArray.optInt(j);
if (subCode != 0) {
subcodes.add(subCode);
}
}
}
items.put(code, subcodes);
}
return items;
}
示例12: getRelations
import org.json.JSONObject; //导入方法依赖的package包/类
private List<RelationType> getRelations(final JSONObject jsonObject) {
JSONArray relation = jsonObject.optJSONArray("relation");
if (relation == null) {
return Collections.emptyList();
}
List<RelationType> relationTypes = new ArrayList<>();
for (int i = 0; i < relation.length(); i++) {
RelationType relationType = RelationType.getRelationType(relation.optString(i));
if (relationType != null) {
relationTypes.add(relationType);
}
}
return relationTypes;
}
示例13: getByTitle
import org.json.JSONObject; //导入方法依赖的package包/类
public JSONObject getByTitle(final String categoryTitle) throws RepositoryException {
final Query query = new Query()
.setFilter(new PropertyFilter(Category.CATEGORY_TITLE, FilterOperator.EQUAL, categoryTitle))
.setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
示例14: initSlider
import org.json.JSONObject; //导入方法依赖的package包/类
private void initSlider(JSONObject object) {
JSONArray slidersArray = object.optJSONArray("sliders");
if (slidersArray == null || slidersArray.length() <= 0) {
this.sliders = null;
} else {
this.sliders = HomeSlider.parseSliders(slidersArray.toString());
}
initHeadAd();
}
示例15: Stats
import org.json.JSONObject; //导入方法依赖的package包/类
public Stats(JSONObject obj) throws JSONException {
timezone = TimeZone.getTimeZone(obj.getString("3"));
entries = new ArrayList<>();
JSONArray entriesArray = obj.optJSONArray("1");
if (entriesArray == null) return; // There are no entries, it's not an error!
for (int i = 0; i < entriesArray.length(); i++)
entries.add(new Entry(entriesArray.getJSONObject(i)));
}