博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
用阿里fastJson解析Json字符串
阅读量:4464 次
发布时间:2019-06-08

本文共 1778 字,大约阅读时间需要 5 分钟。

一下总结来自工作代码:

1.第一种情况:

通过服务器端发送http请求获取的接送字符串。

     String jsonStr = HttpRequestUtil.sendGet(config.getAddress() + config.getPorts() + config.getFind(), "");     //把接送字符串解析成json对象进行操作        JSONObject jb = JSONObject.parseObject(jsonStr);        //取“value”的键值,value里面是个json数组        List jsonArray = jb.getJSONArray("value");        //把json数组转为json字符串        String jsonString = JSONObject.toJSONString(jsonArray);        //又把json字符串转为java集合得到我们需要的数据        List
budgetTargetProjectTemplateJsons = JSONObject.parseArray(jsonString, TemplateJson.class);
public class TemplateJson {        private String acctCode;    private String parentAcctCode;        private String acctName;        }

 

2.第二种情况:

接收前端传来的json字符串。

2.1前端代码:

通过ajax发送

$.ajax({        type: "post",        url: "/xx/xx/xx/bianzhi",        data: {             excelJson:JSON.stringify(tableJson),//格式化为json字符串            },            success: function (result) {             if (result.status == 0) {  //弹出层关闭范例                 parent.parent.layer.close(parent.parent.layer.index);             }             if (result.message != null) {                 parent.parent.parent.layer.msg(result.message)             }         },         error: function (XMLHttpRequest, textStatus, errorThrown) {             layer.msg('{"status":"' + XMLHttpRequest.status + '","readyState":"' + XMLHttpRequest.readyState + '","textStatus":"' + textStatus + '","errorThrown":"' + errorThrown + '"}')         }        });

 

2.2后端代码:

@RequestMapping(value = "bianzhi")ResultJson bianzhi(String tableJson) {    List
budgetExcelJsons = JSON.parseArray(tableJson, BudgetExcelJson.class);  for(BudgetExcelJson budgetExcelJson : budgetExcelJsons) {
  } }

 

转载于:https://www.cnblogs.com/bbllw/p/10662166.html

你可能感兴趣的文章
jquery下php与ajax的数据交换方式
查看>>
魅蓝Note有几种颜色 魅蓝Note哪个颜色好看
查看>>
使用PullToRefresh实现下拉刷新和上拉加载
查看>>
透明度百分比与十六进制转换
查看>>
HBase表预分区
查看>>
NSBundle,UIImage,UIButton的使用
查看>>
vue-cli3 中console.log报错
查看>>
GridView 中Item项居中显示
查看>>
UML类图五种关系与代码的对应关系
查看>>
如何理解作用域
查看>>
从无到满意offer,你需要知道的那些事
查看>>
P1516 青蛙的约会 洛谷
查看>>
SDOI2011 染色
查看>>
JQuery EasyUI combobox动态添加option
查看>>
面向连接的TCP概述
查看>>
前端快捷方式 [记录]
查看>>
亲测可用,解决端口被占用的指令!!
查看>>
MySQL--视图、触发器、事务、存储过程、内置函数、流程控制、索引
查看>>
Django--数据库查询操作
查看>>
自定义配置文件的使用
查看>>