【问题标题】:how to receive a json data from url in restlet for @GET in java?java - 如何从restlet中的url接收json数据以获取Java中的@GET?
【发布时间】:2014-12-30 06:52:44
【问题描述】:

这是我的代码

public class JustinApplication extends Application {
  public synchronized Restlet createInboundRoot() {
    Router router = new Router();

    router.attach("/forresource/{id}", JustinResource.class);       
    return router;
  }
}

我正在尝试通过 URL 发送一个 JSon 数据

{"ID":"324"}.

我想在我的资源类中接收 json 数据。我只能得到这样的字符串 %7B%22ID%22:%22324%22%7D 。但我需要完全相同的数据。 如何使用 restlet 做到这一点?

【问题讨论】:

    标签: java json url get restlet-2.0


    【解决方案1】:

    你得到这个 %7B%22ID%22:%22324%22%7D 因为值 {"ID":"324"} 得到了 URL-Enecoded 发送请求的时间。

    您需要对其进行 URL 解码,您将获得您的价值。

    String jsonParam = URLDecoder.decode(paramVal, "UTF8");
    

    现在你可以使用 jsonParam,它会有{"ID":"324"}

    查看here以了解更多信息

    【讨论】:

      猜你喜欢
      • 2012-04-17
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 2014-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多