我一直在寻找来自 Restlet官方教程的源代码。
我正在尝试使用教程中的 Android 应用程序访问 Restlet 服务器,我只得到 JSON 响应,而不是 Java 对象。我尝试使用所有库和扩展,没有任何效果。当我点击教程网址时(http://restlet-example-serialization.appspot.com/contacts/123),我得到了所需的响应。有任何想法吗?顺便说一句,我只是在示例中使用服务器 (GAE),而不是 GWT 前端。
我一直在寻找来自 Restlet官方教程的源代码。
我正在尝试使用教程中的 Android 应用程序访问 Restlet 服务器,我只得到 JSON 响应,而不是 Java 对象。我尝试使用所有库和扩展,没有任何效果。当我点击教程网址时(http://restlet-example-serialization.appspot.com/contacts/123),我得到了所需的响应。有任何想法吗?顺便说一句,我只是在示例中使用服务器 (GAE),而不是 GWT 前端。
使用 GSOn 将 json 转换为 java 对象。您可以从谷歌获得 GSON 作为其代码:
http://code.google.com/p/google-gson/
另一种方式:
Response res = client.handle(req);
ObjectRepresentation<Item> obj = new ObjectRepresentation<Item>(res.getEntity());
Item item = obj.getObject();