本文整理匯總了Java中com.alibaba.fastjson.JSONArray.get方法的典型用法代碼示例。如果您正苦於以下問題:Java JSONArray.get方法的具體用法?Java JSONArray.get怎麽用?Java JSONArray.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.alibaba.fastjson.JSONArray
的用法示例。
在下文中一共展示了JSONArray.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createConfig
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public static LogcenterConfig createConfig(JSONObject jsonInput) throws LogConsumerException {
String productLine = String.valueOf(jsonInput.get("productLine"));
String appName = String.valueOf(jsonInput.get("appName"));
QueryBuilder qb = QueryBuilders.queryStringQuery("productLine:'" + productLine + "' AND appName:'" + appName + "'");
SearchResponse response = ElasticsearchClient.getClient()
.prepareSearch(Constants.METADATA_INDEX)
.setTypes(Constants.METADATA_TYPE)
.setQuery(qb)
.get();
JSONObject jsonObject = JSON.parseObject(response.toString());
JSONArray hitArray = (JSONArray) jsonObject.getJSONObject("hits").get("hits");
if (hitArray.size() == 0) {
throw new LogConsumerException("index does not exist,please check the configuration of the .logcenter index");
}
JSONObject document = (JSONObject) hitArray.get(0);
String jsonStr = document.get("_source").toString();
return JSONObject.parseObject(jsonStr, LogcenterConfig.class);
}
示例2: test_string
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public void test_string() throws Exception {
char[] chars = new char[1024];
Arrays.fill(chars, '0');
StringBuilder buf = new StringBuilder();
buf.append("[\"");
for (int i = 0; i < 16; ++i) {
buf.append("\\\\");
buf.append(new String(chars));
}
buf.append("\"]");
String text = buf.toString();
JSONArray array = (JSONArray) JSON.parse(text);
Assert.assertEquals(1, array.size());
String item = (String) array.get(0);
Assert.assertEquals(16 * 1024 + 16, item.length());
for (int i = 0; i < 16; ++i) {
Assert.assertTrue(item.charAt(i * 1025) == '\\');
for (int j = 0; j < 1024; ++j) {
Assert.assertTrue(item.charAt(i * 1025 + j + 1) == '0');
}
}
}
示例3: test_string
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public void test_string() throws Exception {
char[] chars = new char[1024];
Arrays.fill(chars, '0');
StringBuilder buf = new StringBuilder();
buf.append("[\"");
for (int i = 0; i < 16; ++i) {
buf.append("\\\"");
buf.append(new String(chars));
}
buf.append("\"]");
String text = buf.toString();
JSONArray array = (JSONArray) JSON.parse(text);
Assert.assertEquals(1, array.size());
String item = (String) array.get(0);
Assert.assertEquals(16 * 1024 + 16, item.length());
for (int i = 0; i < 16; ++i) {
Assert.assertTrue(item.charAt(i * 1025) == '\"');
for (int j = 0; j < 1024; ++j) {
Assert.assertTrue(item.charAt(i * 1025 + j + 1) == '0');
}
}
}
示例4: convertJSONArrayToArray
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private static Object convertJSONArrayToArray(JSONArray ja, Class c, Registry<Class> r) {
Object result = Array.newInstance(c, ja.size());
for (int i = 0; i < ja.size(); i++) {
Object lookup = ja.get(i);
Object value = null;
if (lookup != null) {
if (lookup.getClass().equals(JSONObject.class))
value = convertJSONObjectToMessage((JSONObject) lookup, c, r);
else if (lookup.getClass().equals(JSONArray.class)) // this is not actually allowed in ROS
value = convertJSONArrayToArray((JSONArray) lookup, c.getComponentType(), r);
else
value = convertJSONPrimitiveToPrimitive(lookup, c);
Array.set(result, i, value);
}
}
return result;
}
示例5: format
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
/**
* @param responseArray
* @return
*/
public static JSONArray format(final JSONArray responseArray) {
Log.i(TAG, "format responseArray = \n" + JSON.toJSONString(responseArray));
if (responseArray == null || responseArray.isEmpty()) {
Log.i(TAG, "format responseArray == null || responseArray.isEmpty() >> return response;");
return responseArray;
}
JSONArray transferredArray = new JSONArray();
Object value;
for (int i = 0; i < responseArray.size(); i++) {
value = responseArray.get(i);
if (value instanceof JSONArray) {//轉化JSONArray內部的APIJSON Array
transferredArray.add(format((JSONArray) value));
} else if (value instanceof JSONObject) {//JSONObject,往下一級提取
transferredArray.add(format((JSONObject) value));
} else {//其它Object,直接填充
transferredArray.add(responseArray.get(i));
}
}
Log.i(TAG, "format return transferredArray = " + JSON.toJSONString(transferredArray));
return transferredArray;
}
示例6: initialize
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@PostConstruct
private void initialize() {
logconfigMap = new ConcurrentHashMap<>();
SearchResponse response = ElasticsearchClient.getClient()
.prepareSearch(Constants.METADATA_INDEX)
.setTypes(Constants.METADATA_TYPE)
.get();
JSONObject jsonObject = JSON.parseObject(response.toString());
JSONArray hitArray = (JSONArray) jsonObject.getJSONObject("hits").get("hits");
for (int i = 0; i < hitArray.size(); i++) {
JSONObject document = (JSONObject) hitArray.get(i);
String jsonStr = document.get("_source").toString();
LogcenterConfig config = JSONObject.parseObject(jsonStr, LogcenterConfig.class);
String key = buildCacheMapKey(config.getProductLine(), config.getAppName());
logconfigMap.put(key, config);
}
}
示例7: prepareArguments
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
private Object[] prepareArguments(Type[] paramClazzs, JSONArray args) throws Exception {
Object[] params = new Object[paramClazzs.length];
Object value;
Type paramClazz;
for (int i = 0; i < paramClazzs.length; i++) {
paramClazz = paramClazzs[i];
if(i>=args.size()){
if(!paramClazz.getClass().isPrimitive()) {
params[i] = null;
continue;
}else {
throw new Exception("[prepareArguments] method argument list not match.");
}
}
value = args.get(i);
if (paramClazz == JSONObject.class) {
params[i] = value;
} else if(JSCallback.class == paramClazz){
if(value instanceof String){
params[i] = new SimpleJSCallback(mInstanceId,(String)value);
}else{
throw new Exception("Parameter type not match.");
}
} else {
params[i] = WXReflectionUtils.parseArgument(paramClazz,value);
}
}
return params;
}
示例8: test_string
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public void test_string() throws Exception {
char[] chars = new char[1024];
Arrays.fill(chars, '0');
StringBuilder buf = new StringBuilder();
buf.append("[\"");
for (int i = 0; i < 16; ++i) {
buf.append("\\\\");
buf.append("\\\"");
buf.append(new String(chars));
}
buf.append("\"]");
String text = buf.toString();
JSONArray array = (JSONArray) JSON.parse(text);
Assert.assertEquals(1, array.size());
String item = (String) array.get(0);
Assert.assertEquals(16 * 1024 + 32, item.length());
for (int i = 0; i < 16; ++i) {
Assert.assertTrue(item.charAt(i * 1026) == '\\');
Assert.assertTrue(item.charAt(i * 1026 + 1) == '\"');
for (int j = 0; j < 1024; ++j) {
Assert.assertTrue(item.charAt(i * 1026 + j + 2) == '0');
}
}
}
示例9: test_stackTrace
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public void test_stackTrace() throws Exception {
StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
String text = JSON.toJSONString(stackTrace, SerializerFeature.WriteClassName);
JSONArray array = (JSONArray) JSON.parse(text);
for (int i = 0; i < array.size(); ++i) {
StackTraceElement element = (StackTraceElement) array.get(i);
Assert.assertEquals(stackTrace[i].getFileName(), element.getFileName());
Assert.assertEquals(stackTrace[i].getLineNumber(), element.getLineNumber());
Assert.assertEquals(stackTrace[i].getClassName(), element.getClassName());
Assert.assertEquals(stackTrace[i].getMethodName(), element.getMethodName());
}
}
示例10: test_vehicleTotalDetail
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@Test
public void test_vehicleTotalDetail() {
File file = new File("D:\\dayData.json");
String json = readToString(file, "UTF-8");
JSONObject jsonObject = JSON.parseObject(json);
JSONArray dataArray = jsonObject.getJSONArray("data");
System.out.println(jsonObject.toJSONString());
double result = 0;
for (int i = 0; i < dataArray.size(); i++) {
JSONObject temp = (JSONObject) dataArray.get(i);
result += Double.parseDouble(temp.get("mileage").toString());
}
System.out.println(result);
}
示例11: toList
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
/**
* JSONArray轉為List
* @param array json數組
* @return 轉化後的List
*/
public static List<Object> toList(JSONArray array){
List<Object> list = new ArrayList<Object>();
for(int i = 0; i < array.size(); i++) {
Object value = array.get(i);
if(value instanceof JSONArray) {
value = toList((JSONArray) value);
}else if(value instanceof JSONObject) {
value = toMap((JSONObject) value);
}
list.add(value);
}
return list;
}
示例12: getOne
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@Override
public JSONObject getOne(Condition query, String... keys) throws DBException
{
JSONArray list = getJSONs(query, FIND_ONE, keys);
Object obj = list.size() > 0 ? list.get(0) : null;
JSONObject jsonObject = (JSONObject) obj;
return jsonObject;
}
示例13: getOne
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
@Override
public JSONObject getOne(Condition query, String... keys) throws DBException
{
JSONArray list = getJSONs(query, FIND_ONE, keys);
Object obj = list.size() > 0 ? list.get(0) : null;
return (JSONObject) obj;
}
示例14: arrayToMap
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
protected List<Object> arrayToMap(JSONArray array) {
List<Object> list = new ArrayList<Object>();
int size = array.size();
for (int i = 0; i < size; i++) {
Object v = array.get(i);
if (v instanceof JSONArray) {
list.add(arrayToMap((JSONArray) v));
} else if (v instanceof JSONObject) {
list.add(jsonToMap((JSONObject) v));
} else {
list.add(v);
}
}
return list;
}
示例15: loadPositions
import com.alibaba.fastjson.JSONArray; //導入方法依賴的package包/類
public void loadPositions(String json) {
if (StringHelper.isEmpty(json)) {
return;
}
Long inode = 0L, pos = 0L, number = 0L;
String file = "";
JSONArray positionRecords = JSONArray.parseArray(json);
for (int i = 0; i < positionRecords.size(); i++) {
JSONObject positionObject = (JSONObject) positionRecords.get(i);
inode = positionObject.getLong("inode");
pos = positionObject.getLong("pos");
file = positionObject.getString("file");
// add line number
number = positionObject.getLongValue("num");
for (Object v : Arrays.asList(inode, pos, file)) {
Preconditions.checkNotNull(v, "Detected missing value in position file. " + "inode: " + inode
+ ", pos: " + pos + ", path: " + file);
}
TailFile tf = tailFiles.get(inode);
try {
if (tf != null && tf.updatePos(file, inode, pos, number)) {
tailFiles.put(inode, tf);
}
else {
// add old tail file into memory
maybeReloadMap.put(inode, new Long[] { pos, number });
if (log.isDebugEnable()) {
log.debug(this, "add old&inInterrupt file: " + file + ", inode: " + inode + ", pos: " + pos);
}
}
}
catch (IOException e) {
log.err(this, "TailFile updatePos FAILED.", e);
}
}
}