java APPLICATION_JSON 无法解析或不是字段
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/33647939/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
APPLICATION_JSON cannot be resolved or is not a field
提问by Ghita
I have a problem producing JSON in my application.
我在我的应用程序中生成 JSON 时遇到问题。
I'm trying a tutorial about Consuming Java Restful Web Service with AngularJS. I've created a dynamic web project as my RESTful server and then added the following libraries:
我正在尝试有关使用 AngularJS 使用 Java Restful Web 服务的教程。我创建了一个动态 Web 项目作为我的 RESTful 服务器,然后添加了以下库:
- asm-3.3.1.jar
- Hymanson-core-asl-1.9.9.jar
- Hymanson-jaxrs-1.9.9.jar
- Hymanson-mapper-asl-1.9.9.jar
- Hymanson-xc-1.9.9.jar
- jersey-bundle-1.8.jar
- jersey-bundle-1.9.jar
- jersey-client-1.9.jar
- jersey-core-1.9.jar
- jersey-json-1.9.jar
- jersey-media-json-jettison-2.4.jar
- jersey-server-1.9.1.jar
- jersey-servlet-1.12.jar
- jettison-1.3.3.jar
- jsr311-api-1.1.1.jar
- asm-3.3.1.jar
- Hymanson-core-asl-1.9.9.jar
- Hymanson-jaxrs-1.9.9.jar
- Hymanson-mapper-asl-1.9.9.jar
- Hyman逊-xc-1.9.9.jar
- jersey-bundle-1.8.jar
- jersey-bundle-1.9.jar
- jersey-client-1.9.jar
- jersey-core-1.9.jar
- 球衣-json-1.9.jar
- jersey-media-json-jettison-2.4.jar
- jersey-server-1.9.1.jar
- 球衣servlet-1.12.jar
- jettison-1.3.3.jar
- jsr311-api-1.1.1.jar
Here is the service :
这是服务:
package ws;
import java.awt.PageAttributes.MediaType;
import java.util.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import entities.Prospect;
@Path("prospect")
public class ProspectRestful {
@GET
@Path("findall")
@Produces(MediaType.APPLICATION_JSON)
public List<Prospect> findAll(){
List<Prospect> result = new ArrayList<Prospect>();
result.add(new Prospect(35, "Name 35", "last35"));
result.add(new Prospect(36, "Name 36", "last36"));
return result;
}
}
But I'm getting this error:
但我收到此错误:
APPLICATION_JSON cannot be resolved or is not a field.
APPLICATION_JSON 无法解析或不是字段。
I've seen in another question that jersey-media-json-jettison-2.4.jar should be there so I added it but no sign.
我在另一个问题中看到 jersey-media-json-jettison-2.4.jar 应该在那里,所以我添加了它但没有任何迹象。
I'm sure I'm not using a Maven project, in the same tutorial they didn't use Maven either.
我确定我没有使用 Maven 项目,在同一个教程中他们也没有使用 Maven。
回答by shazin
Remove this
删除这个
import java.awt.PageAttributes.MediaType;
and add this
并添加这个
import javax.ws.rs.core.MediaType;
回答by lakhani69
In my case it is not working, so if anyone facing the error then try...
就我而言,它不起作用,所以如果有人遇到错误,请尝试...
import org.springframework.http.MediaType;
It worked for me...
它对我有用...