如何在 Spring 中从 HttpServletResponse 检索 JSON 对象?
我有一个 Spring 控制器,我必须在其中从 URLConnection 读取 JSON 对象。目前,我通过逐行读取连接的输入流来执行此操作。基本上我正在逐行阅读响应的文本内容。
是否有任何 JSON api 可用于直接从 URLConnection 填充 JSON 对象?有什么可以和 Spring 集成的吗?
I have a Spring controller in which I have to read a JSON object from a URLConnection. Currently I am doing this by reading from the connection's input stream line by line. Basically I am reading the text contents of the response line by line.
Is there any JSON api that I could use to populate the JSON object directly from the URLConnection? Anything that integrates with Spring?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
也许这相关?本质上,实现 JsonView。
Perhaps this is related? Essentially, implementing JsonView.
http://jackson .codehaus.org/1.6.0/javadoc/org/codehaus/jackson/JsonFactory.html#createJsonParser(java.io.InputStream) 这可能会有所帮助,因为 URLConnection 可以返回 InputStream 您想要与什么集成。春天,顺便说一句?
http://jackson.codehaus.org/1.6.0/javadoc/org/codehaus/jackson/JsonFactory.html#createJsonParser(java.io.InputStream) This could help, as URLConnection can return InputStream. What do you want to integrate with Spring, btw?