2010-04-07 73 views
0

我有這個問題:JSON與struts2,如何填充此對象?

如何從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[]座標,它的工作原理,但只有點幾何。

我使用struts2 2.1.8和json插件。

非常感謝。

回答

-1

您應該嘗試將「座標」定義爲列表。