Java Code Examples for com.alibaba.fastjson.JSONArray#iterator()

The following examples show how to use com.alibaba.fastjson.JSONArray#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DeployService.java    From PeonyFramwork with Apache License 2.0 6 votes vote down vote up
public JSONObject delDeployServer(String projectId, int id,int page){

        DeployServer deployServer = dataService.selectObject(DeployServer.class,"projectId=? and id=?",projectId,id);
        if(deployServer == null){
            throw new ToClientException(SysConstantDefine.InvalidParam,"server id is not exist!projectId={}, id={}",projectId,id);
        }
        dataService.delete(deployServer);

        JSONObject ret = getDeployServerList(projectId,page,serverPageSize);
        JSONArray array = ret.getJSONArray("deployServers");
        Iterator<Object> it = array.iterator();
        while (it.hasNext()){
            JSONObject jsonObject = (JSONObject)it.next();
            if(jsonObject.getInteger("id")==id){
                it.remove();
                break;
            }
        }

        return ret;
    }
 
Example 2
Source File: TagResult.java    From aliyun-tsdb-java-sdk with Apache License 2.0 6 votes vote down vote up
public static List<TagResult> parseList(String json) {
    JSONArray array = JSON.parseArray(json);
    List<TagResult> arrayList = new ArrayList<TagResult>(array.size());

    Iterator<Object> iterator = array.iterator();
    while (iterator.hasNext()) {
        JSONObject object = (JSONObject) iterator.next();
        Set<Entry<String, Object>> entrySet = object.entrySet();
        for (Entry<String, Object> entry : entrySet) {
            String key = entry.getKey();
            String value = entry.getValue().toString();
            TagResult tagResult = new TagResult(key, value);
            arrayList.add(tagResult);
            break;
        }
    }

    return arrayList;
}
 
Example 3
Source File: KeysController.java    From UIAutomatorWD with MIT License 6 votes vote down vote up
@Override
public NanoHTTPD.Response get(RouterNanoHTTPD.UriResource uriResource, Map<String, String> urlParams, NanoHTTPD.IHTTPSession session) {
    String sessionId = urlParams.get("sessionId");
    Map<String, String> body = new HashMap<String, String>();
    UiDevice mDevice = Elements.getGlobal().getmDevice();
    JSONObject result = null;
    try {
        session.parseBody(body);
        String postData = body.get("postData");
        JSONObject jsonObj = JSON.parseObject(postData);
        JSONArray keycodes = (JSONArray)jsonObj.get("value");
        for (Iterator iterator = keycodes.iterator(); iterator.hasNext();) {
            int keycode = (int) iterator.next();
            mDevice.pressKeyCode(keycode);
        }
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(result, sessionId).toString());
    } catch (Exception e) {
        return NanoHTTPD.newFixedLengthResponse(getStatus(), getMimeType(), new Response(Status.UnknownError, sessionId).toString());
    }
}
 
Example 4
Source File: BeanUtils.java    From frpMgr with MIT License 5 votes vote down vote up
public static <D> List<D> tranJSONArray(JSONArray arr, Class<D> destClass) {
    List<D> ret = new ArrayList<>();
    Iterator<Object> iterator = arr.iterator();
    while (iterator.hasNext()) {
        JSONObject next = (JSONObject) iterator.next();
        try {
            ret.add(destClass.getConstructor(JSONObject.class).newInstance(next));
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("tranJSONArray exception", e);
        }
    }
    return ret;
}
 
Example 5
Source File: NavBuilder.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param user
 * @return
 */
public JSONArray getNavPortal(ID user) {
    ConfigEntry config = getLayoutOfNav(user);
    if (config == null) {
        return NAVS_DEFAULT;
    }

    // 过滤
    JSONArray navs = (JSONArray) config.getJSON("config");
    for (Iterator<Object> iter = navs.iterator(); iter.hasNext(); ) {
        JSONObject nav = (JSONObject) iter.next();
        JSONArray subNavs = nav.getJSONArray("sub");

        if (subNavs != null && !subNavs.isEmpty()) {
            for (Iterator<Object> subIter = subNavs.iterator(); subIter.hasNext(); ) {
                JSONObject subNav = (JSONObject) subIter.next();
                if (isFilterNav(subNav, user)) {
                    subIter.remove();
                }
            }

            // 无子级,移除主菜单
            if (subNavs.isEmpty()) {
                iter.remove();
            }
        } else if (isFilterNav(nav, user)) {
            iter.remove();
        }
    }
    return navs;
}
 
Example 6
Source File: ChartManager.java    From rebuild with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 丰富图表数据 title, type
 *
 * @param charts
 */
protected void richingCharts(JSONArray charts) {
       for (Iterator<Object> iter = charts.iterator(); iter.hasNext(); ) {
           JSONObject ch = (JSONObject) iter.next();
           ID chartid = ID.valueOf(ch.getString("chart"));
           ConfigEntry e = getChart(chartid);
           if (e == null) {
               iter.remove();
               continue;
           }

           ch.put("title", e.getString("title"));
           ch.put("type", e.getString("type"));
       }
}
 
Example 7
Source File: TestTagResult.java    From aliyun-tsdb-java-sdk with Apache License 2.0 5 votes vote down vote up
@Test
public void testJSONToResult() {
    String json = "[{\"host\":\"127.0.0.1\"},{\"host\":\"127.0.0.1\"},{\"host\":\"127.0.0.1.012\"}]";

    try {
        JSONArray array = JSON.parseArray(json);
        // System.out.println(array);
        Assert.assertEquals(array.toString(),
                "[{\"host\":\"127.0.0.1\"},{\"host\":\"127.0.0.1\"},{\"host\":\"127.0.0.1.012\"}]");
        List<TagResult> arrayList = new ArrayList<TagResult>(array.size());

        Iterator<Object> iterator = array.iterator();
        while (iterator.hasNext()) {
            JSONObject object = (JSONObject) iterator.next();
            Set<Entry<String, Object>> entrySet = object.entrySet();
            for (Entry<String, Object> entry : entrySet) {
                String key = entry.getKey();
                Assert.assertNotEquals(key, null);
                Object valueObject = entry.getValue();
                Assert.assertNotEquals(key, null);
                String value = valueObject.toString();
                TagResult tagResult = new TagResult(key, value);
                arrayList.add(tagResult);
                break;
            }
        }
        Assert.assertEquals(arrayList.size(), 3);
    } catch (Exception ex) {
        ex.printStackTrace();
    }

}
 
Example 8
Source File: ArgumentsUtil.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
public static void fromArrayToBundle(Bundle bundle, String key, Object array) {
    if (bundle != null && !TextUtils.isEmpty(key) && array != null) {
        if (array instanceof String[]) {
            bundle.putStringArray(key, (String[]) ((String[]) array));
        } else if (array instanceof byte[]) {
            bundle.putByteArray(key, (byte[]) ((byte[]) array));
        } else if (array instanceof short[]) {
            bundle.putShortArray(key, (short[]) ((short[]) array));
        } else if (array instanceof int[]) {
            bundle.putIntArray(key, (int[]) ((int[]) array));
        } else if (array instanceof long[]) {
            bundle.putLongArray(key, (long[]) ((long[]) array));
        } else if (array instanceof float[]) {
            bundle.putFloatArray(key, (float[]) ((float[]) array));
        } else if (array instanceof double[]) {
            bundle.putDoubleArray(key, (double[]) ((double[]) array));
        } else if (array instanceof boolean[]) {
            bundle.putBooleanArray(key, (boolean[]) ((boolean[]) array));
        } else if (array instanceof char[]) {
            bundle.putCharArray(key, (char[]) ((char[]) array));
        } else {
            if (!(array instanceof JSONArray)) {
                throw new IllegalArgumentException("Unknown array type " + array.getClass());
            }

            ArrayList arraylist = new ArrayList();
            JSONArray jsonArray = (JSONArray) array;
            Iterator it = jsonArray.iterator();

            while (it.hasNext()) {
                JSONObject object = (JSONObject) it.next();
                arraylist.add(fromJsonToBundle(object));
            }

            bundle.putParcelableArrayList(key, arraylist);
        }

    }
}
 
Example 9
Source File: LoginServiceImpl.java    From xiaoV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void webWxGetContact() {
	String url = String.format(URLEnum.WEB_WX_GET_CONTACT.getUrl(), core
			.getLoginInfo().get(StorageLoginInfoEnum.url.getKey()));
	Map<String, Object> paramMap = core.getParamMap();
	HttpEntity entity = httpClient.doPost(url, JSON.toJSONString(paramMap));

	try {
		String result = EntityUtils.toString(entity, Consts.UTF_8);
		// System.out.println("webWxGetContact:" + result);//CPP
		JSONObject fullFriendsJsonList = JSON.parseObject(result);
		// 查看seq是否为0,0表示好友列表已全部获取完毕,若大于0,则表示好友列表未获取完毕,当前的字节数(断点续传)
		long seq = 0;
		long currentTime = 0L;
		List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
		if (fullFriendsJsonList.get("Seq") != null) {
			seq = fullFriendsJsonList.getLong("Seq");
			currentTime = new Date().getTime();
		}
		core.setMemberCount(fullFriendsJsonList
				.getInteger(StorageLoginInfoEnum.MemberCount.getKey()));
		JSONArray member = fullFriendsJsonList
				.getJSONArray(StorageLoginInfoEnum.MemberList.getKey());
		// 循环获取seq直到为0,即获取全部好友列表 ==0:好友获取完毕 >0:好友未获取完毕,此时seq为已获取的字节数
		while (seq > 0) {
			// 设置seq传参
			params.add(new BasicNameValuePair("r", String
					.valueOf(currentTime)));
			params.add(new BasicNameValuePair("seq", String.valueOf(seq)));
			entity = httpClient.doGet(url, params, false, null);

			params.remove(new BasicNameValuePair("r", String
					.valueOf(currentTime)));
			params.remove(new BasicNameValuePair("seq", String.valueOf(seq)));

			result = EntityUtils.toString(entity, Consts.UTF_8);
			fullFriendsJsonList = JSON.parseObject(result);

			if (fullFriendsJsonList.get("Seq") != null) {
				seq = fullFriendsJsonList.getLong("Seq");
				currentTime = new Date().getTime();
			}

			// 累加好友列表
			member.addAll(fullFriendsJsonList
					.getJSONArray(StorageLoginInfoEnum.MemberList.getKey()));
		}
		core.setMemberCount(member.size());
		for (Iterator<?> iterator = member.iterator(); iterator.hasNext();) {
			JSONObject o = (JSONObject) iterator.next();
			if ((o.getInteger("VerifyFlag") & 8) != 0) { // 公众号/服务号
				core.getPublicUsersList().add(o);
			} else if (Config.API_SPECIAL_USER.contains(o
					.getString("UserName"))) { // 特殊账号
				core.getSpecialUsersList().add(o);
			} else if (o.getString("UserName").indexOf("@@") != -1) { // 群聊
				if (!core.getGroupIdList()
						.contains(o.getString("UserName"))) {
					core.getGroupNickNameList()
							.add(o.getString("NickName"));
					core.getGroupIdList().add(o.getString("UserName"));
					core.getGroupList().add(o);
				}
			} else if (o.getString("UserName").equals(
					core.getUserSelf().getString("UserName"))) { // 自己
				core.getContactList().remove(o);
			} else { // 普通联系人
				core.getContactList().add(o);
			}
		}
		return;
	} catch (Exception e) {
		LOG.error(e.getMessage(), e);
	}
	return;
}