【问题标题】:Json with struts2, How to populate this object?Json with struts2,如何填充这个对象?
【发布时间】:2010-04-07 14:02:16
【问题描述】:

我有这个问题:

如何从 struts2 动作填充这个对象? 我的操作毫无问题地填充了很多我的对象,但我对 JSON 输入有限制。我的输入是这样的:

我现在不知道如何填充。几何类可以有double[]double[][]double[][][],因为JSON 输入可以有多种几何类型。 Json 示例:

{ "geometry" : { "coordinates" : [331450.0638554565,5128924.597221361],
            "type" : "Point"
          } 

{ "geometry" : { "coordinates" : [  
              [ 331889.57676804002,5130491.5563009996],
                      [ 330991.44168580999,5129555.2027046001],
                      [ 331450.0638554565,5128924.597221361]
                      ],
                "type" : "Linestring"
              }

{ "geometry" : { "coordinates" : [ [ 
              [ 331889.57676804002,5130491.5563009996],
                      [ 330991.44168580999,5129555.2027046001],
                      [ 331450.0638554565,5128924.597221361],
                      [ 332749.49333611998,5128332.2102522003],
                      [ 333953.37653145002,5129153.9083062001],
                      [ 333972.48578852002,5129822.7323035998],
                      [ 332615.72853664,5129880.0600747997],
                      [ 331889.57676804002,5130491.5563009996] ] ],
                "type" : "Polygon"
              }

我的对象是这样的:

public class Geometry {


    private String type;
    private Object coordinates;

    public String getType() {
        return type;
    }
    public void setType(String type) {
        this.type = type;
    }
    public Object getCoordinates() {
        return coordinates;
    }
    public void setCoordinates(Object coordinates) {
        this.coordinates = coordinates;
    }
}

如果我将几何类修改为 double[] 坐标,它可以工作,但仅适用于点几何。

我使用带有 json 插件的 struts2 2.1.8。

非常感谢。

【问题讨论】:

    标签: java json struts2


    【解决方案1】:

    您应该尝试将“坐标”定义为列表。

    【讨论】:

      猜你喜欢
      • 2019-10-04
      • 1970-01-01
      • 1970-01-01
      • 2020-07-10
      • 1970-01-01
      • 2015-11-19
      • 1970-01-01
      • 1970-01-01
      • 2018-08-11
      相关资源
      最近更新 更多