这是我的阿曼班:
import org.codehaus.jackson.annotate.JsonIgnoreProperties;
@JsonIgnoreProperties(ignoreUnknown=true)
public class Aman
{
public static class Title
{
private String title;
public String getTitle(){ return title; }
public String setTitle(String s){ return title = s; }
}
private int id;
private int year;
private int total;
public void id(int i){ id = i; }
public void year(int y){ year = y; }
public void total(int t){ total =t; }
}
这是映射值的 Movie 类:
import java.io.File;
import java.io.IOException;
import org.codehaus.jackson.JsonGenerationException;
import org.codehaus.jackson.map.JsonMappingException;
import org.codehaus.jackson.map.ObjectMapper;
import java.net.*;
public class Movie
{
public static void main(String[] args) throws MalformedURLException, URISyntaxException, IOException {
Aman a = new Aman();
ObjectMapper mapper = new ObjectMapper();
URL RT = new URL("http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=gzscv4f8zqse75w94mmp37zz&q=Toy+Story+3&page_limit=1").toURI().toURL();
a = mapper.readValue(RT, Aman.class);
}
}
我一遍又一遍地遇到同样的异常。
难道我做错了什么?
这是不断发生的异常:
Exception:Exception in thread "main" org.codehaus.jackson.map.exc.UnrecognizedPropertyException: Unrecognized field "total" (Class Aman), not marked as ignorable
at [Source: http://api.rottentomatoes.com/api/public/v1.0/movies.json?apikey=gzscv4f8zqse75w94mmp37zz&q=Toy+Story+3&page_limit=1; line: 31, column: 11] (through reference chain: Aman["total"])