本文整理汇总了Java中net.sf.json.JSONArray.toString方法的典型用法代码示例。如果您正苦于以下问题:Java JSONArray.toString方法的具体用法?Java JSONArray.toString怎么用?Java JSONArray.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.sf.json.JSONArray
的用法示例。
在下文中一共展示了JSONArray.toString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getOption
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* replacement的value为String类型时,直接根据key替换,否则转为Json》String后再替换
* @author ack (chenzhao) @DATE: Aug 23, 2017
* @param replacement
* @return 返回生成option字符串
*/
public String getOption(LinkedHashMap<String, Object> replacement){
Set<Entry<String, Object>> entrySet=replacement.entrySet();
Iterator<Entry<String, Object>> iterator=entrySet.iterator();
while (iterator.hasNext()) {
Entry<String, Object>entry=(Entry<String, Object>) iterator.next();
//如果value非String,则将value转为json再转为String
String value=entry.getValue()+"";
Object objValue=entry.getValue() ;
if(!(objValue instanceof String)){
if(objValue instanceof List||objValue instanceof Object[]){//如果是数组或集合
JSONArray jsonArray=JSONArray.fromObject(objValue);
value=jsonArray.toString();
}else{
JSONObject jsonObjecct=JSONObject.fromObject(entry.getValue());
value=jsonObjecct.toString();
}
}
//根据key替换Option字符串里的字符
chartString=chartString.replace(entry.getKey()+"", value);
}
return chartString;
}
示例2: updateSex
import net.sf.json.JSONArray; //导入方法依赖的package包/类
public String updateSex() {
stuList = service.loadStuList();
// 获取男生数量和女生数量
JSONArray jsonArray = JSONArray.fromObject(stuList);
result = jsonArray.toString();
try {
response.setHeader("Cache-Control", "no-cache");
response.setContentType("aplication/json;charset=UTF-8");
response.getWriter().print(result);// 发送到页面
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(result);
return null;
}
示例3: sendOnlineData
import net.sf.json.JSONArray; //导入方法依赖的package包/类
public void sendOnlineData(JSONArray data) throws IOException {
String uri = address + "api/active/receiver/data";
LinkedList<FormBodyPart> partsList = new LinkedList<>();
String dataStr = data.toString();
log.debug("Sending active test data: " + dataStr);
partsList.add(new FormBodyPart("data", new StringBody(dataStr)));
query(createPost(uri, partsList), 202);
}
示例4: checkDynasty
import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Action("checkDynasty")
public String checkDynasty(){
dynastyList=bookService.checkDynasty();
JSONArray jsonArray = JSONArray.fromObject(dynastyList);
//ajax返回客户端
jsonArray.toString();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/html;charset=UTF-8");
try {
response.getWriter().write(jsonArray.toString());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例5: checkStyle
import net.sf.json.JSONArray; //导入方法依赖的package包/类
@Action("checkStyle")
public String checkStyle(){
styleList=bookService.checkStyle();
JSONArray jsonArray = JSONArray.fromObject(styleList);
//ajax返回客户端
jsonArray.toString();
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/html;charset=UTF-8");
try {
response.getWriter().write(jsonArray.toString());
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
示例6: showAllGoodsType
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 显示所有商品类型信息
*
* @param response
*/
@RequestMapping(value = "/showAllGoodsType")
@Override
public void showAllGoodsType(HttpServletResponse response)
{
try
{
//查询全部商品类型信息
List<GoodsType8JPA> goodsTypeList = goodsTypeService
.findAll();
if (goodsTypeList.size() == 0)
{
throw new
Exception("TinyShop8Controller_." +
"查询所有商品类型信息失败!并没有任何商品类型信息");
}
//写入json
JSONArray jsonArray = new JSONArray();
for (Iterator<GoodsType8JPA> it = goodsTypeList.iterator(); it.hasNext(); )
{
JSONObject jsonObject = new JSONObject();
GoodsType8JPA goodsType = it.next();
//名字
jsonObject.put("goodsTypeName", goodsType.getTypeName());
//排序
jsonObject.put("goodsTypeSort", goodsType.getTypeSort());
//别名
jsonObject.put("goodsTypeAlias", goodsType.getTypeAlias());
//上级类型
jsonObject.put("goodsParent", "parent");
jsonArray.add(jsonObject);
}
String baseStr = "{\"total\":" + goodsTypeList.size() + ",\"rows\":";
baseStr = baseStr + jsonArray.toString() + "}";
returnJson(baseStr, response);
}
catch (Exception ex)
{
printStackTrace(ex);
}
}
示例7: responseArraySuccess
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 返回成功
* @param obj 输出对象
* @return 输出成功的JSON格式数据
*/
public String responseArraySuccess(Object obj){
JSONArray jsonObj = null;
if(obj != null){
logger.info("后端返回对象:{}", obj);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new JsonDateValueProcessor());
jsonObj = JSONArray.fromObject(obj, jsonConfig);
logger.info("后端返回数据:" + jsonObj);
}
logger.info("输出结果:{}", jsonObj.toString());
return jsonObj.toString();
}
示例8: loadTree
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* @return JSONArray. The JSON array of deployed web service in application.
*/
public JSONArray loadTree() {
if (log.isDebugEnabled()) {
log.debug("Loading tree started");
}
JSONArray jsonArray = createTree();
String jsonResult = jsonArray.toString();
if (log.isDebugEnabled()) {
log.debug("result: " + jsonResult); // just for debug purposes-
}
return jsonArray;
}
示例9: loadTree
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* @return JSONArray. The JSON array of deployed web service in application.
*/
public JSONArray loadTree() throws JAXBException, MalformedURLException {
if (log.isDebugEnabled()) {
log.debug("Loading tree started");
}
JSONArray jsonArray = createTree();
String jsonResult = jsonArray.toString();
if (log.isDebugEnabled()) {
log.debug("result: " + jsonResult); // just for debug purposes-
}
return jsonArray;
}
示例10: showAllGoods
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 显示所有商品信息
*
* @param response
*/
//@RequestMapping(value = "/showAllGoods")
@Deprecated
@Override
public void showAllGoods(HttpServletResponse response)
{
try
{
//首先查询所有商品信息
final List<Goods8JPA> goodsList = goodsService
.findAll();
if (goodsList.size() == 0)
{
throw new
Exception("TinyShop8Controller_.查询所有商品信息失败!并没有任何商品信息");
}
//写入json
JSONArray jsonArray = new JSONArray();
for (Iterator<Goods8JPA> it = goodsList.iterator(); it.hasNext(); )
{
JSONObject jsonObject = new JSONObject();
Goods8JPA goods = it.next();
//名称
jsonObject.put("goodsName", goods.getGoodsName());
//编号
jsonObject.put("goodsProNo", goods.getGoodsProNo());
//添加时间
jsonObject.put("goodsAddDate", goods.getGoodsAddDate());
//市场价
jsonObject.put("goodsMarketPrice", goods.getGoodsMarketPrice());
//所属类型
jsonObject.put("goodsType", "type");
//品牌
jsonObject.put("goodsBrand", "brand");
jsonArray.add(jsonObject);
}
String baseStr = "{\"total\":" + goodsList.size() + ",\"rows\":";
baseStr = baseStr + jsonArray.toString() + "}";
returnJson(baseStr, response);
}
catch (Exception ex)
{
printStackTrace(ex);
}
}
示例11: auth
import net.sf.json.JSONArray; //导入方法依赖的package包/类
/**
* 请求权限授权页面
*
* @param userId
* @return
*/
@RequestMapping(value = AuthManageConst.PATH_AUTH, method = RequestMethod.POST)
public @ResponseBody Map<String, Object> auth(@RequestParam String r_id) {
// 取得菜单一览
List<Function> functionList = functionService.listAllFunction();
// 取得授权权限权限
Role roleSearch = new Role();
roleSearch.setR_id(r_id);
Role role = roleService.getRoleById(roleSearch);
if (role != null) {
String roleRights = role.getR_function();
// 判断该权限是否存在功能权限
if (StringUtil.notEmpty(roleRights)) {
// 循环菜单一览
for (Function function : functionList) {
// 设置权限是否存在该一级菜单的访问权限
function.setHasFunction(RightsHelper.testRights(roleRights, function.getF_no()));
// 判断是否存在此级菜单访问权限
if (function.isHasFunction()) {
// 取得二级菜单一览
List<Function> subRightsList = function.getSubFunction();
// 循环二级菜单一览
for (Function sub : subRightsList) {
// 设置权限是否存在该二级菜单的访问权限
sub.setHasFunction(RightsHelper.testRights(roleRights, sub.getF_no()));
// 判断是否存在此级菜单访问权限
if (sub.isHasFunction()) {
// 取得三级菜单一览
List<Function> nextSubRightsList = sub.getSubFunction();
// 循环三级菜单一览
for (Function nexSub : nextSubRightsList) {
// 设置权限是否存在该三级菜单的访问权限
nexSub.setHasFunction(RightsHelper.testRights(roleRights, nexSub.getF_no()));
}
}
}
}
}
}
}
// 将菜单一览转换为json格式
JSONArray arr = JSONArray.fromObject(functionList);
// 将json格式的菜单一览转换为字符串
String json = arr.toString();
// 置换为指定的ID
json = json.replaceAll(AuthManageConst.ATTRIBUTE_NAME_F_NO, AuthManageConst.ATTRIBUTE_NAME_ID)
.replaceAll(AuthManageConst.ATTRIBUTE_NAME_F_NAME, AuthManageConst.ATTRIBUTE_NAME_NAME)
.replaceAll(AuthManageConst.ATTRIBUTE_NAME_SUB_FUNCTION, AuthManageConst.ATTRIBUTE_NAME_CHILDREN)
.replaceAll(AuthManageConst.ATTRIBUTE_NAME_HAS_FUNCTION, AuthManageConst.ATTRIBUTE_NAME_CHECKED);
Map<String, Object> map = new HashMap<String, Object>();
// 返回处理结果
map.put(AuthManageConst.ATTRIBUTE_NAME_RESULT, Boolean.TRUE);
// 返回菜单一览
map.put(AuthManageConst.ATTRIBUTE_NAME_Z_TREE_NODES, json);
// 返回角色ID
map.put(AuthManageConst.ATTRIBUTE_NAME_R_ID, r_id);
return map;
}