获取 Java 条带的 JSON 数据
当执行 getJSON 函数时,我想向服务器发送一些数据(我使用的是 java Stripes 框架),我只是想知道它会是什么数据类型?
例如,
$.getJSON("/tictactoe/get_next_move",
{board: displayedBoardArray},
function(data) {
var json = data;
}
如果我想取回它,那么该板的类型是什么? displayedBoardArray 是 var 数组类型。检索板类型并将其打印出来后,如下所示:
private String[] board;
public String[] getBoard(){
return board;
}
public void setBoard(String[]board){
this.board = board;
}
...
System.out.println("board: " +board); //This retrieved a null
...
String[]
是错误的数据类型吗?
When performing a getJSON function, and I want to send some data to the server (I'm using a java Stripes framework), I was jut wondering, what datatype will it be?
e.g.
$.getJSON("/tictactoe/get_next_move",
{board: displayedBoardArray},
function(data) {
var json = data;
}
What is the type of board if I want to retrieve it? displayedBoardArray is a var Array type. After retrieving the board type and printing it out like this:
private String[] board;
public String[] getBoard(){
return board;
}
public void setBoard(String[]board){
this.board = board;
}
...
System.out.println("board: " +board); //This retrieved a null
...
Is String[]
a wrong datatype?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我之所以插话只是因为还没有比我更好的人。没有什么比试图超越别人更快得到好的答案的了。 ;-)
displayedBoardArray 采用什么形式?如果它实际上是一个包含键:值对的对象,它应该作为一系列 GET 参数和值进入服务器。如果它只是一个原始的 JavaScript 数组,我认为你无法做到这一点。
不过,一般来说,一旦您将有效数据发送到服务器,它将作为 GET 参数进入,您将使用某种方法获取该参数。我不能说你的 Stripes 方法是否做到了这一点。同样,一般来说,理论上您可以拥有一个创建数组的方法,或者一个创建字符串(使用逗号分隔或类似分隔符)的方法。我想这取决于获取 GET 参数值的方法。
I'm going to chime in only because better people than me have not yet. Nothing gets good answers quicker than someone trying to one-up someone else. ;-)
What form does displayedBoardArray take? If it's actually an object containing key:value pairs, it should come into the server as a series of GET parameters and values. If it's just a raw JavaScript array, I don't think you can do that.
In general, though, once you are sending valid data to the server, it will come in as GET parameter(s) which you will grab using some sort of method. I couldn't say if your Stripes method is doing that. Again, generally speaking, you can theoretically have a method that will create an array, or a method that will create a string (with comma separations or similar). I guess it depends on the method that's grabbing the GET parameter values.