• 字符串或者对象 和 JSON 相互转换


    客户端:

      $scope.saveSelectObj = function(){
                var objectArray =new Array();
                var obj;
                for(var i=0;i<$scope.selectObject.length;i++ )
                {
                    obj = new Object();
                    obj.Id = $scope.selectObject[i].value;
                    obj.Name = $scope.selectObject[i].text;
                    objectArray.push(obj);
                }
                alert(angular.toJson(objectArray));
            }

    就是最后一句话  angular.toJson

    服务端:

    把字符串转换成 JSON对象 JSONObject.parseObject(String)

    public ServiceStatus save(String userId, String json) {
            JSONObject jsonObject = JSONObject.parseObject(json);
            DashboardWidget widget = new DashboardWidget();
            widget.setUserId(userId);
            widget.setName(jsonObject.getString("name"));
            widget.setData(jsonObject.getString("data"));
            widget.setCategoryName(jsonObject.getString("categoryName"));
            if (StringUtils.isEmpty(widget.getCategoryName())) {
                widget.setCategoryName("默认分类");
            }
            Map<String, Object> paramMap = new HashMap<String, Object>();
            paramMap.put("widget_name", widget.getName());
            paramMap.put("user_id", widget.getUserId());
            paramMap.put("category_name", widget.getCategoryName());
    
            if (widgetDao.countExistWidgetName(paramMap) <= 0) {
                widgetDao.save(widget);
                return new ServiceStatus(ServiceStatus.Status.Success, "success");
            } else {
                return new ServiceStatus(ServiceStatus.Status.Fail, "Duplicated name");
            }
        }

    从客户端JSON 转为服务端JSON

        public ServiceStatus save(String userId, String json) {
            JSONObject jsonObject = JSONObject.parseObject(json);
            DashboardDatasource datasource = new DashboardDatasource();
            datasource.setUserId(userId);
            datasource.setName(jsonObject.getString("name"));
            datasource.setType(jsonObject.getString("type"));
            datasource.setConfig(jsonObject.getString("config"));
    ...
  • 相关阅读:
    C++ primer 简读
    C++函数及类方法(待补充)
    C++参数传递-复制和引用
    c++动态分配内存
    C++内存与指针
    c++循环
    C++容器vector及迭代器对象iterator
    c++字符类型一些知识点
    CNN中卷积运算转化成矩阵乘法的实现——img2col+GEMM大矩阵乘法
    046 LeetCode go
  • 原文地址:https://www.cnblogs.com/Bruce_H21/p/12598860.html
Copyright © 2020-2023  润新知