本文整理汇总了Java中net.sf.json.JSONArray.toArray方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.toArray方法的具体用法?Java JSONArray.toArray怎么用?Java JSONArray.toArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.toArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: jsonArrayToBeanArray
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* Converts the input array JSON structure into an array of instances of the
* beanClassName. If the beanClassName is null, then an arrays of instances
* of org.apache.commons.beanutils.DynaBean will be returned.
*
* @param input
* input array as a JSON structure.
* @param beanClassName
* the name of the bean class.
* @return the input array JSON structure as an array of instances of the beanClassName.
* @throws ClassNotFoundException if the beanClassName is invalid.
*/
public static Object[] jsonArrayToBeanArray(String input, String beanClassName) throws ClassNotFoundException {
if (log.isDebugEnabled())
log.debug("Converting JSON '" + input + "' into an array of instances of " + beanClassName);
registerCustomMorphers();
Class beanClass = beanClassName != null ? Class.forName(beanClassName) : null;
JSONArray jsonArray = JSONArray.fromObject(input);
Object[] beans = beanClass != null ? (Object[]) JSONArray.toArray(jsonArray, beanClass) : (Object[]) JSONArray.toArray(jsonArray);
if (log.isDebugEnabled())
log.debug("Converted to: " + Arrays.toString(beans));
return beans;
}
示例2: jsonArrayToBeanArray
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* Converts the input array JSON structure into an array of instances of the
* beanClassName. If the beanClassName is null, then an arrays of instances
* of org.apache.commons.beanutils.DynaBean will be returned.
*
* @param input
* input array as a JSON structure.
* @param beanClassName
* the name of the bean class.
* @return the input array JSON structure as an array of instances of the beanClassName.
* @throws ClassNotFoundException if the beanClassName is invalid.
*/
public static Object[] jsonArrayToBeanArray(String input, String beanClassName) throws ClassNotFoundException {
if (log.isDebugEnabled())
log.debug("Converting JSON '" + input + "' into an array of instances of " + beanClassName);
registerCustomMorphers();
Class beanClass = beanClassName != null ? Class.forName(beanClassName) : null;
JSONArray jsonArray = JSONArray.fromObject(input);
Object[] beans = beanClass != null ? (Object[]) JSONArray.toArray(jsonArray, beanClass) : (Object[]) JSONArray.toArray(jsonArray);
if (log.isDebugEnabled())
log.debug("Converted to: " + Arrays.toString(beans));
return beans;
}
示例3: getObjectArrayFromJson
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 从json数组中得到相应java数组 json形如:["123", "456"]
*
* @param jsonString
* @return
*/
public static Object[] getObjectArrayFromJson(String jsonString) {
JSONArray jsonArray = JSONArray.fromObject(jsonString);
return jsonArray.toArray();
}