本文整理汇总了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();
}
}