【问题标题】:Arraylist is coming as string in while sending in webserviceArraylist 在 Web 服务中发送时以字符串形式传入
【发布时间】:2013-10-31 08:39:06
【问题描述】:
 JSONObject myObject = new JSONObject();
  try {


        testVoList.add(new TestVO(1L, "HAI1"));
        testVoList.add(new TestVO(2L, "HAI2"));

        myObject.put("name", testVoList);          


    } catch (JSONException ex) {
     }
    String s = URLEncoder.encode(myObject.toString(), "UTF-8");     
    URL url = new URL("urlName/"+s);

用于接收数据的网络服务代码:

@POST
@Path("/urlName/{test}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String saveSurveyresponseData(@PathParam("test") JSONObject responseData)
{
     JSONArray.fromObject(responseData.getString("name")).get(0);           
            return "HAI";
}

我在这里得到test.TestVO@c2ea3f(Hashcode)

JSONArray.fromObject(responseData.getString("name")).get(0);

如何访问我的网络服务中的对象值列表。

你能建议我一个解决方案吗?

【问题讨论】:

  • 你用 jersy 标记你的问题:你是说 jersey 吗?
  • @ruffp jersy 网络服务
  • 我没有找到 jersy web-services 的任何参考,你能分享一个链接吗?
  • 那就是泽西岛……

标签: java json web-services arraylist jersey


【解决方案1】:

我相信以下说法:

 JSONArray.fromObject(responseData.getString("name")).get(0);

正在返回列表。因此,只需将其分配给此处提到的列表引用:

List<TestVO> listOfTestVO = JSONArray.fromObject(responseData.getString("name")).get(0);

现在只需将元素获取为:

listOfTestVO.get(1);

【讨论】:

  • 我还需要在服务器端创建 testVo 吗?
  • TestVO 未在服务器端创建
  • @PSR TestVO 实际上是您的 DTO,它应该存在于客户端和服务器端。
猜你喜欢
  • 1970-01-01
  • 2013-07-17
  • 1970-01-01
  • 2011-08-18
  • 2016-07-25
  • 2012-05-21
  • 1970-01-01
  • 2015-08-16
  • 2020-05-15
相关资源
最近更新 更多