[英]I can not determine the type of Array
我的客戶端(As3)將這個數組發送到我的服務器(Java),該函數具有以下功能:
{2={y=16.0, x=17.0}, 1={y=17.0, x=17.0}, 0={y=18.0, x=17.0}}
但是我無法確定類型。
我試過了:String [],Object []等。
服務器端:
public void MaSuperFonction(Object[] $path){ ... }
客戶端 :
this.groupedList[0] = {x:this.startX,y:this.startY};
this.groupedList[1] = {x:this.startX,y:this.startY};
this.groupedList[2] = {x:this.startX,y:this.startY};
var path = this.groupedList[0];
if(this.groupedList.length > 1)
{
var i = 1;
while(i < this.groupedList.length)
{
path = path.concat(this.groupedList[i]);
i = i + 1;
}
}
this.nc.call('MaSuperFonction',path);
但是沒有成功。
Method MaSuperFonction with parameters [{2={y=16.0, x=17.0}, 1={y=17.0, x=17.0}, 0={y=18.0, x=17.0}}] not found
我寧願說這是Map<Integer, Point>>
,其中Point
類可以聲明為:
class Point {
private Double x;
private Double y;
// getters/setters
}
您應該理解,它是鍵=值對的序列,不能用數組表示(數組的每個單元格僅包含一個元素)。
看起來您的客戶端正在發送二維雙精度數組,請參見下面的示例代碼,了解如何創建二維雙精度數組並對其進行迭代:-
public class SOArrayTest {
public static void main(String[] args) {
double[][] a = new double[3][2];
a[0][0] = 16.0;
a[0][1] = 17.0;
a[1][0] = 18.0;
a[1][1] = 19.0;
a[2][0] = 20.0;
a[2][1] = 21.0;
for(int i=0; i<3; i++) {
for(int j=0; j<2; j++) {
System.out.print(a[i][j] + " ");
}
System.out.println();
}
}
}
您還可以對上面的代碼進行一些修改,然后在服務器端的二維雙數組中接受它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.