本文整理匯總了Java中com.alibaba.fastjson.JSONArray.iterator方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.iterator方法的具體用法?Java JSONArray.iterator怎麽用?Java JSONArray.iterator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONArray
的用法示例。
在下文中一共展示了JSONArray.iterator方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: login
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@ApiOperation("用戶登入")
@PostMapping("/login")
public ResponseEntity login(@RequestBody @Valid IndexLoginFormat format) {
UserEntity userEntity = userService.getUserByLogin(format.getEmail(),
new Md5Hash(format.getPassword()).toString());
if (userEntity == null)
throw new WebErrorException("用戶名密碼錯誤");
JSONArray array = userEntity.getPermission();
Iterator<Object> it = array.iterator();
Set<String> permission = new HashSet<>();
while (it.hasNext()) {
permission.add(it.next().toString());
}
String token = JWTUtil.sign(userEntity.getUid(), userEntity.getRole(), permission, userEntity.getPassword());
Cache<String, String> authCache = CacheController.getAuthCache();
authCache.put(token, userEntity.getPassword());
return new ResponseEntity("登入成功", token);
}
示例2: parseList
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
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;
}
示例3: decodeSFSArray
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private IArray decodeSFSArray(JSONArray jsa) {
CArrayLite sfsArray = CArrayLite.newInstance();
Iterator<Object> iter = jsa.iterator();
while (iter.hasNext()) {
Object value = iter.next();
DataWrapper decodedObject = this.decodeJsonObject(value);
if (decodedObject == null) {
throw new IllegalStateException("(json2sfarray) Could not decode value for object: " + value);
}
sfsArray.add(decodedObject);
}
return sfsArray;
}
示例4: get
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@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());
}
}
示例5: fromArrayToBundle
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
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);
}
}
}
示例6: testJSONToResult
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@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();
}
}