zoukankan      html  css  js  c++  java
  • 用阿里fastJson解析Json字符串

    一下总结来自工作代码:

    1.第一种情况:

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

         String jsonStr = HttpRequestUtil.sendGet(config.getAddress() + config.getPorts() + config.getFind(), "");
         //把接送字符串解析成json对象进行操作
            JSONObject jb = JSONObject.parseObject(jsonStr);
            //取“value”的键值,value里面是个json数组
            List<Object> jsonArray = jb.getJSONArray("value");
            //把json数组转为json字符串
            String jsonString = JSONObject.toJSONString(jsonArray);
            //又把json字符串转为java集合得到我们需要的数据
            List<TemplateJson> 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<BudgetExcelJson> budgetExcelJsons = JSON.parseArray(tableJson, BudgetExcelJson.class);
      for(BudgetExcelJson budgetExcelJson : budgetExcelJsons) {

      }
    }
  • 相关阅读:
    05,WP8的文件和存储
    04,WP8的async和await
    01,Windows Phone 8 介绍
    开源工作流引擎
     RMS集成的时候会出这样那样的问题
    ASP.NET第一次访问慢的完美解决方案(MVC,Web Api)
    SharePoint2010关闭我的网站(个人网站)
    SMSServer的网关配置
    文件间调用变量(extern,include)[转]
    [转]安装SMSServer作为Windows系统服务
  • 原文地址:https://www.cnblogs.com/bbllw/p/10662166.html
Copyright © 2011-2022 走看看