Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/380.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在GWT中将Java对象(POJO)编码为JSON字符串 客观的_Java_Json_Gwt_Json Rpc_Resty Gwt - Fatal编程技术网

在GWT中将Java对象(POJO)编码为JSON字符串 客观的

在GWT中将Java对象(POJO)编码为JSON字符串 客观的,java,json,gwt,json-rpc,resty-gwt,Java,Json,Gwt,Json Rpc,Resty Gwt,我想使用JSON-RPC在客户端发送: {"jsonrpc":"2.0","method":"RegisterValues","params":[["Planets","Stars"]],"id":2} 我的尝试 使用Resty GWT: public interface testService extends RestService { @Produces("application/json") @POST public void myCall(Params myp

我想使用JSON-RPC在客户端发送:

{"jsonrpc":"2.0","method":"RegisterValues","params":[["Planets","Stars"]],"id":2}
我的尝试 使用Resty GWT:

public interface testService extends RestService {

    @Produces("application/json")
    @POST
    public void myCall(Params myparams, MethodCallback<Response> callback );

    public class Params {
          String jsonrpc = "2.0";
          String method;
          //String[] params;
          Map<String, String> params;
          int id;

          public void setId(int id){
              this.id = id;
          }

          public void setMethod(String method){
              this.method = method;
          }
                          }

          public void setParams(Map<String, String> params){
              this.params = params;
          }

        }
我不知道如何获得这些魔法:
[[“行星”]

我尝试使用
字符串[]
,但结果是:
[“行星”]

String[][]
给出的错误是它还不受支持

骇人听闻的黑客 如果我在我的
testService
中将
字符串传递为:

String myparams = "{\"jsonrpc\":\"2.0\",\"method\":\"RegisterValues\",\"params\":[[\"FPlanets\"]],\"id\":2}";
这是可行的,但显然这是可怕的

我尝试使用GSON对POJO进行编码,但GWT不允许反射。我尝试使用将对象解析为一个“字符串”,但无法找出我在
gwt.xml
文件中需要的

有什么想法吗?

试试这个

List<List<String>> params;
表示一个
列表
,其中“params”是POJO中的变量名

POJO:


Params
对象发送回客户端。

感谢您提供的详细答案
String myparams = "{\"jsonrpc\":\"2.0\",\"method\":\"RegisterValues\",\"params\":[[\"FPlanets\"]],\"id\":2}";
List<List<String>> params;
Map<String, String> params;
"params":[["Planets","Stars"]]
class Params implements Serializable {
    private String jsonrpc;
    private String method;
    private int id;
    private List<List<String>> params;
    ...
   //getter/setter
   //default constructor
}
String myparams = "{\"jsonrpc\":\"2.0\",\"method\":\"RegisterValues\",\"params\":[[\"FPlanets\"]],\"id\":2}";
Params params=gson.fromJson(myparams,Params.class);
System.out.println(params.params+"-"+params.id);