APPLICATION_JSON无法解析或不是字段 [英] APPLICATION_JSON cannot be resolved or is not a field

查看:123
本文介绍了APPLICATION_JSON无法解析或不是字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序中生成JSON时遇到问题.

I have a problem producing JSON in my application.

我正在尝试有关使用AngularJS使用Java Restful Web服务的教程. 我已经创建了一个动态Web项目作为RESTful服务器,然后添加了以下库:

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:

  • asm-3.3.1.jar
  • jackson-core-asl-1.9.9.jar
  • jackson-jaxrs-1.9.9.jar
  • jackson-mapper-asl-1.9.9.jar
  • jackson-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
  • jackson-core-asl-1.9.9.jar
  • jackson-jaxrs-1.9.9.jar
  • jackson-mapper-asl-1.9.9.jar
  • jackson-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

这是服务:

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;
    }
}

但是我收到此错误:

APPLICATION_JSON无法解析或不是字段.

APPLICATION_JSON cannot be resolved or is not a field.

我在另一个问题中看到jersey-media-json-jettison-2.4.jar应该存在,所以我添加了它但没有任何标志.

I've seen in another question that jersey-media-json-jettison-2.4.jar should be there so I added it but no sign.

我确定我没有使用Maven项目,在同一教程中,他们也没有使用Maven.

I'm sure I'm not using a Maven project, in the same tutorial they didn't use Maven either.

推荐答案

删除此

import java.awt.PageAttributes.MediaType;

并添加

import javax.ws.rs.core.MediaType;

这篇关于APPLICATION_JSON无法解析或不是字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆