本文整理匯總了Java中com.alibaba.fastjson.JSONArray.getJSONObject方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.getJSONObject方法的具體用法?Java JSONArray.getJSONObject怎麽用?Java JSONArray.getJSONObject使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONArray
的用法示例。
在下文中一共展示了JSONArray.getJSONObject方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rolePermission
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@Override
public int rolePermission(JSONArray datas, int id) {
List<Integer> deleteIds = new ArrayList<>();
for (int i = 0; i < datas.size(); i ++) {
JSONObject json = datas.getJSONObject(i);
if (!json.getBoolean("checked")) {
deleteIds.add(json.getIntValue("id"));
} else {
// 新增權限
UpmsRolePermission upmsRolePermission = new UpmsRolePermission();
upmsRolePermission.setRoleId(id);
upmsRolePermission.setPermissionId(json.getIntValue("id"));
upmsRolePermissionMapper.insertSelective(upmsRolePermission);
}
}
// 刪除權限
if (deleteIds.size() > 0) {
UpmsRolePermissionExample upmsRolePermissionExample = new UpmsRolePermissionExample();
upmsRolePermissionExample.createCriteria()
.andPermissionIdIn(deleteIds)
.andRoleIdEqualTo(id);
upmsRolePermissionMapper.deleteByExample(upmsRolePermissionExample);
}
return datas.size();
}
示例2: getProcessOrders
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private List<ProcessOrder> getProcessOrders(ProcessPo processPo) {
JSONArray jsonArray = JSON.parseArray(processPo.getProcessOrder());
List<ProcessOrder> processOrders = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
ProcessOrder processOrder = new ProcessOrder();
JSONObject jsonObject = jsonArray.getJSONObject(i);
processOrder.setProcessOrder(jsonObject.getInteger("processOrder"));
try {
processOrder.setProcessClass(Class.forName(jsonObject.getString("processClazz")));
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
processOrders.add(processOrder);
}
return processOrders;
}
示例3: permission
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@Override
public int permission(JSONArray datas, int id) {
for (int i = 0; i < datas.size(); i ++) {
JSONObject json = datas.getJSONObject(i);
if (json.getBoolean("checked")) {
// 新增權限
UpmsUserPermission upmsUserPermission = new UpmsUserPermission();
upmsUserPermission.setUserId(id);
upmsUserPermission.setPermissionId(json.getIntValue("id"));
upmsUserPermission.setType(json.getByte("type"));
upmsUserPermissionMapper.insertSelective(upmsUserPermission);
} else {
// 刪除權限
UpmsUserPermissionExample upmsUserPermissionExample = new UpmsUserPermissionExample();
upmsUserPermissionExample.createCriteria()
.andPermissionIdEqualTo(json.getIntValue("id"))
.andTypeEqualTo(json.getByte("type"));
upmsUserPermissionMapper.deleteByExample(upmsUserPermissionExample);
}
}
return datas.size();
}
示例4: getTags
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public static List<Tag> getTags (boolean useCache) throws APIException {
if (DEBUG) Log.i(TAG, "-> getTags");
try {
String text = NetworkUtil.get(ApiManager.API_TAGS, useCache);
if (DEBUG) Log.i(TAG, "-> get -> success");
JSONObject root = JSON.parseObject(text);
JSONArray data = root.getJSONArray("data");
List<Tag> tags = new ArrayList<>();
for (int i = 0; i < data.size(); i ++) {
JSONObject object = data.getJSONObject(i);
Tag tag = getTag(object.getInteger("id"), object);
if (DEBUG) Log.i(TAG, "Adding " + tag.toString());
tags.add(tag);
}
return tags;
} catch (IOException|JSONException e) {
throw new APIException(e);
}
}
示例5: pinch
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private static boolean pinch(JSONArray actions) throws Exception {
for (int i = 0; i < actions.size(); i++) {
JSONObject action = actions.getJSONObject(i);
if(!pinch(action)) {
return false;
}
}
return true;
}
示例6: getParamsOrHeadersMap
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private HashMap<String, String> getParamsOrHeadersMap(JSONArray array) {
HashMap<String, String> resultMap = new HashMap<>();
if (null != array && array.size() > 0) {
int loop = 0;
while (loop < array.size()) {
JSONObject jsonObject = array.getJSONObject(loop);
resultMap.put(jsonObject.getString("name"), jsonObject.getString("value"));
loop++;
}
}
return resultMap;
}
示例7: tap
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private static boolean tap(JSONArray actions) throws Exception {
for (int i = 0; i < actions.size(); i++) {
JSONObject action = actions.getJSONObject(i);
if(!tap(action)) {
return false;
}
}
return true;
}
示例8: convert
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@Override
public ArrayList<MultipleItemEntity> convert() {
final JSONArray array = JSON.parseObject(getJsonData()).getJSONArray("data");
final int size = array.size();
for (int i = 0; i < size; i++) {
final JSONObject data = array.getJSONObject(i);
final int id = data.getInteger("id");
final String name = data.getString("name");
final String phone = data.getString("phone");
final String address = data.getString("address");
final boolean isDefault = data.getBoolean("default");
final MultipleItemEntity entity = MultipleItemEntity.builder()
.setItemType(AddressItemType.ITEM_ADDRESS)
.setField(MultipleFields.ID, id)
.setField(MultipleFields.NAME, name)
.setField(MultipleFields.TAG, isDefault)
.setField(AddressItemFields.PHONE, phone)
.setField(AddressItemFields.ADDRESS, address)
.build();
ENTITIES.add(entity);
}
return ENTITIES;
}
示例9: queryOne
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
/**
* 查詢成功時,結果為null或json。
*/
public JResponse queryOne(WObject wObject, DBSource dbSource, AdvancedQuery advancedQuery) {
QuerySettings querySettings = new QuerySettings();
querySettings.setLimit(1).setSkip(0);
JResponse jResponse = advancedQuery(wObject, dbSource, advancedQuery, querySettings);
if (jResponse.isSuccess()) {
JSONArray array = jResponse.getResult();
JSONObject jsonObject = array.size() > 0 ? array.getJSONObject(0) : null;
jResponse.setResult(jsonObject);
}
return jResponse;
}
示例10: convert
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
final List<SectionBean> convert(String json) {
final List<SectionBean> dataList = new ArrayList<>();
final JSONArray dataArray = JSON.parseObject(json).getJSONArray("data");
final int size = dataArray.size();
for (int i = 0; i < size; i++) {
final JSONObject data = dataArray.getJSONObject(i);
final int id = data.getInteger("id");
final String title = data.getString("section");
//添加title
final SectionBean sectionTitleBean = new SectionBean(true, title);
sectionTitleBean.setId(id);
sectionTitleBean.setIsMore(true);
dataList.add(sectionTitleBean);
final JSONArray goods = data.getJSONArray("goods");
//商品內容循環
final int goodSize = goods.size();
for (int j = 0; j < goodSize; j++) {
final JSONObject contentItem = goods.getJSONObject(j);
final int goodsId = contentItem.getInteger("goods_id");
final String goodsName = contentItem.getString("goods_name");
final String goodsThumb = contentItem.getString("goods_thumb");
//獲取內容
final SectionContentItemEntity itemEntity = new SectionContentItemEntity();
itemEntity.setGoodsId(goodsId);
itemEntity.setGoodsName(goodsName);
itemEntity.setGoodsThumb(goodsThumb);
//添加內容
dataList.add(new SectionBean(itemEntity));
}
//商品內容循環結束
}
//Section循環結束
return dataList;
}
示例11: getMemMetrics
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
/**
* 內存
* @param containerName
* @param container
* @return
* @throws IOException
*/
private List<CollectObject> getMemMetrics(String containerName,JSONObject container,JSONObject machineInfo) throws IOException {
List<CollectObject> collectObjectList = new ArrayList<>();
boolean hasMemory = container.getJSONObject("spec").getBoolean("has_memory");
collectObjectList.add(new CollectObject(containerName,"has_memory",hasMemory ? "1" : "0",""));
if(hasMemory){
long machineMemory = machineInfo.getLong("memory_capacity");//機器總內存
long limitMemory = container.getJSONObject("spec").getJSONObject("memory").getLong("limit");//容器的內存限製大小
if(limitMemory > machineMemory || limitMemory < 0){
//若內存限製大於機器總內存或小於0,使用機器總內存為總內存大小
limitMemory = machineMemory;
}
JSONArray stats = container.getJSONArray("stats");
int count = stats.size();
JSONObject stat = stats.getJSONObject(count - 1);
JSONObject memory = stat.getJSONObject("memory");
long usage = memory.getLong("usage");
long cache = memory.getLong("cache");
collectObjectList.add(new CollectObject(containerName,"mem.size.usage", String.valueOf(Maths.div(usage,1024 * 1024)),""));
collectObjectList.add(new CollectObject(containerName,"mem.size.cache", String.valueOf(Maths.div(cache,1024 * 1024)),""));
collectObjectList.add(new CollectObject(containerName,"mem.usage.rate", String.valueOf(Maths.div(usage,limitMemory,5) * 100),""));
collectObjectList.add(new CollectObject(containerName,"mem.cache.rate", String.valueOf(Maths.div(cache,limitMemory,5) * 100),""));
}
return collectObjectList;
}
示例12: scan
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
/**
* 定時掃描遠程配置信息
*/
private boolean scan() {
String listUrl = url + "/list";
String jsonString = httpGet(listUrl);
if (StringUtils.isBlank(jsonString)) {
LogKit.error("can not get remote config info,plase check url : " + listUrl);
return false;
}
JSONArray jsonArray = null;
try {
jsonArray = JSON.parseArray(jsonString);
} catch (Throwable ex) {
LogKit.error("can not parse json : \n" + jsonString + "\n\nfrom url : " + listUrl, ex);
return false;
}
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject jsonObject = jsonArray.getJSONObject(i);
curScan.put(jsonObject.getString("id"), jsonObject.getString("version"));
}
return true;
}
示例13: parseArray
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public static LinkedHashMap<String,BundleListing.BundleInfo> parseArray(String listingStr,LinkedHashMap<String,BundleListing.BundleInfo>currentBundleInfo) throws Exception{
LinkedHashMap<String,BundleListing.BundleInfo> infos= new LinkedHashMap<>();
JSONArray array = JSON.parseArray(listingStr);
for(int x=0; x<array.size(); x++){
JSONObject object = array.getJSONObject(x);
BundleListing.BundleInfo info = new BundleListing.BundleInfo();
info.setName(object.getString("name"));
info.setPkgName(object.getString("pkgName"));
info.setApplicationName(object.getString("applicationName"));
info.setVersion(object.getString("version"));
info.setDesc(object.getString("desc"));
info.setUrl(object.getString("url"));
info.setMd5(object.getString("md5"));
String uniqueTag = object.getString("unique_tag");
if(StringUtils.isEmpty(uniqueTag)){
throw new IOException("uniqueTag is empty");
}
info.setUnique_tag(object.getString("unique_tag"));
if (currentBundleInfo==null) {
info.setCurrent_unique_tag(info.getUnique_tag());
}else {
if (currentBundleInfo.get(info.getPkgName())!= null){
info.setCurrent_unique_tag(currentBundleInfo.get(info.getPkgName()).getUnique_tag());
}
}
infos.put(info.getPkgName(),info);
}
return infos.size()>0 ? infos : null;
}
示例14: getCpuMetrics
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private List<CollectObject> getCpuMetrics(String containerName, JSONObject container) throws IOException, InterruptedException {
List<CollectObject> collectObjectList = new ArrayList<>();
boolean hasCpu = container.getJSONObject("spec").getBoolean("has_cpu");
collectObjectList.add(new CollectObject(containerName,"has_cpu",hasCpu ? "1" : "0",""));
if(hasCpu){
JSONArray stats = container.getJSONArray("stats");
int count = stats.size();
if(count >= 2){
JSONObject stat = stats.getJSONObject(count - 2);
String timestamp = stat.getString("timestamp");
long time = transNanoseconds(timestamp);
JSONObject stat2 = stats.getJSONObject(count - 1);
String timestamp2 = stat2.getString("timestamp");
long time2 = transNanoseconds(timestamp2);
if(time == 0 || time2 == 0){
log.error("CPU利用率采集失敗,時間鍾轉換失敗");
return new ArrayList<>();
}
JSONObject cpu = stat.getJSONObject("cpu");
JSONObject usage = cpu.getJSONObject("usage");
JSONObject cpu2 = stat2.getJSONObject("cpu");
JSONObject usage2 = cpu2.getJSONObject("usage");
long totalTime = time2 - time;
long total = usage.getLong("total");
long user = usage.getLong("user");
long system = usage.getLong("system");
long total2 = usage2.getLong("total");
long user2 = usage2.getLong("user");
long system2 = usage2.getLong("system");
// 皮秒級別進行計算
collectObjectList.add(new CollectObject(containerName,"total.cpu.usage.rate",String.valueOf(Maths.div(total2 - total,totalTime * 1000,5) * 100),""));
collectObjectList.add(new CollectObject(containerName,"user.cpu.usage.rate",String.valueOf(Maths.div(user2 - user,totalTime * 1000,5) * 100),""));
collectObjectList.add(new CollectObject(containerName,"system.cpu.usage.rate",String.valueOf(Maths.div(system2 - system,totalTime * 1000,5) * 100),""));
}
}
return collectObjectList;
}
示例15: getNetMetrics
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private List<CollectObject> getNetMetrics(String containerName,JSONObject container){
List<CollectObject> collectObjectList = new ArrayList<>();
boolean hasNetwork = container.getJSONObject("spec").getBoolean("has_network");
collectObjectList.add(new CollectObject(containerName,"has_network",hasNetwork ? "1" : "0",""));
if(hasNetwork){
JSONArray stats = container.getJSONArray("stats");
int count = stats.size();
JSONObject stat = stats.getJSONObject(count - 1);
JSONObject network = stat.getJSONObject("network");
JSONArray interfaces = network.getJSONArray("interfaces");
for (Object ifObj : interfaces) {
JSONObject ifJson = (JSONObject) ifObj;
String ifName = ifJson.getString("name");
String tag = "ifName=" + ifName;
long rxBytes = ifJson.getLong("rx_bytes");
long rxPackets = ifJson.getLong("rx_packets");
long rxErrors = ifJson.getLong("rx_errors");
long rxDropped = ifJson.getLong("rx_dropped");
long txBytes = ifJson.getLong("tx_bytes");
long txPackets = ifJson.getLong("tx_packets");
long txErrors = ifJson.getLong("tx_errors");
long txDropped = ifJson.getLong("tx_dropped");
collectObjectList.add(new CollectObject(containerName,"net.if.in.bytes",String.valueOf(rxBytes),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.packets",String.valueOf(rxPackets),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.errors",String.valueOf(rxErrors),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.dropped",String.valueOf(rxDropped),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.bytes",String.valueOf(rxBytes),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.packets",String.valueOf(rxPackets),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.errors",String.valueOf(rxErrors),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.in.speed.dropped",String.valueOf(rxDropped),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.bytes",String.valueOf(txBytes),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.packets",String.valueOf(txPackets),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.errors",String.valueOf(txErrors),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.dropped",String.valueOf(txDropped),tag));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.bytes",String.valueOf(txBytes),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.packets",String.valueOf(txPackets),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.errors",String.valueOf(txErrors),tag,CounterType.COUNTER));
collectObjectList.add(new CollectObject(containerName,"net.if.out.speed.dropped",String.valueOf(txDropped),tag,CounterType.COUNTER));
}
}
return collectObjectList;
}