当前位置: 首页>>代码示例>>Java>>正文


Java JSONArray.get方法代码示例

本文整理汇总了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);
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:20,代码来源:LogConfigFactory.java

示例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');    
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:StringTest_00.java

示例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');    
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:StringTest_02.java

示例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;
}
 
开发者ID:ZhouKanZ,项目名称:SweepRobot,代码行数:19,代码来源:JSON.java

示例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;
}
 
开发者ID:TommyLemon,项目名称:APIJSON-Android-RxJava,代码行数:28,代码来源:JSONResponse.java

示例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);

    }
}
 
开发者ID:geeker-lait,项目名称:tasfe-framework,代码行数:21,代码来源:LogConfigCache.java

示例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;
}
 
开发者ID:erguotou520,项目名称:weex-uikit,代码行数:31,代码来源:NativeInvokeHelper.java

示例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');    
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:28,代码来源:StringTest_01.java

示例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());
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:StackTraceElementTest.java

示例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);
}
 
开发者ID:alamby,项目名称:upgradeToy,代码行数:15,代码来源:ParseMileage.java

示例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;
}
 
开发者ID:alamby,项目名称:upgradeToy,代码行数:19,代码来源:ParseEventMap.java

示例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;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:9,代码来源:SqlHandle.java

示例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;
}
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:8,代码来源:SqliteHandle.java

示例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;
}
 
开发者ID:xsonorg,项目名称:tangyuan2,代码行数:16,代码来源:FastJsonConverter.java

示例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);
            }
        }
    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:40,代码来源:ReliableTaildirEventReader.java


注:本文中的com.alibaba.fastjson.JSONArray.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。