- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我对 Jackson 解析器非常陌生。我的代码运行良好,直到今天。我无法找出错误。
Exception in thread "main" com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_ARRAY token
at [Source: line: 1, column: 1095] (through reference chain: JsonGen["platforms"])
at com.fasterxml.jackson.databind.JsonMappingException.from(JsonMappingException.java:163)
at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:588)
at com.fasterxml.jackson.databind.deser.std.JdkDeserializers$StringDeserializer.deserialize(JdkDeserializers.java:90)
at com.fasterxml.jackson.databind.deser.std.JdkDeserializers$StringDeserializer.deserialize(JdkDeserializers.java:59)
at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:336)
at com.fasterxml.jackson.databind.deser.impl.MethodProperty.deserializeAndSet(MethodProperty.java:89)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:290)
at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:112)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:226)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:203)
at com.fasterxml.jackson.databind.deser.std.CollectionDeserializer.deserialize(CollectionDeserializer.java:23)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2563)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1789)
at BossMan.candie(BossMan.java:49)
at Hilda.main(Hilda.java:81)
这里是 URL 调用和对象映射器的代码:
public class BossMan {
public String[] candie () throws JsonParseException, JsonMappingException, IOException
{
URL jsonUrl = new URL("http://www.dishanywhere.com/radish/v20/dol/home/carousels/shows.json");
ObjectMapper objmapper = new ObjectMapper();
List<JsonGen> jsongen = objmapper.readValue(jsonUrl, new TypeReference<List<JsonGen>>() {});
String[] shows = new String [jsongen.size()];
int i = 0;
for(JsonGen element : jsongen) {
shows[i++]=element.getName();
}
return shows;
}
}
这里是 POJO 类:
import java.util.List;
public class JsonGen{
private String _type;
private List cast;
private List clips;
private Common_sense_data common_sense_data;
private String common_sense_id;
private List crew;
private String description;
private List episodes;
private Number franchise_id;
private List genres;
private String guid;
private Images images;
private boolean is_locked;
private boolean is_mobile;
private boolean is_parental_locked;
private String kind;
private String mobile_networks;
private String most_recent_full_episode_added_date;
private String name;
private List networks;
private String platforms;
private List ratings;
private String release_date;
private List season_filters;
private String slug;
private String tms_id;
public String get_type(){
return this._type;
}
public void set_type(String _type){
this._type = _type;
}
public List getCast(){
return this.cast;
}
public void setCast(List cast){
this.cast = cast;
}
public List getClips(){
return this.clips;
}
public void setClips(List clips){
this.clips = clips;
}
public Common_sense_data getCommon_sense_data(){
return this.common_sense_data;
}
public void setCommon_sense_data(Common_sense_data common_sense_data){
this.common_sense_data = common_sense_data;
}
public String getCommon_sense_id(){
return this.common_sense_id;
}
public void setCommon_sense_id(String common_sense_id){
this.common_sense_id = common_sense_id;
}
public List getCrew(){
return this.crew;
}
public void setCrew(List crew){
this.crew = crew;
}
public String getDescription(){
return this.description;
}
public void setDescription(String description){
this.description = description;
}
public List getEpisodes(){
return this.episodes;
}
public void setEpisodes(List episodes){
this.episodes = episodes;
}
public Number getFranchise_id(){
return this.franchise_id;
}
public void setFranchise_id(Number franchise_id){
this.franchise_id = franchise_id;
}
public List getGenres(){
return this.genres;
}
public void setGenres(List genres){
this.genres = genres;
}
public String getGuid(){
return this.guid;
}
public void setGuid(String guid){
this.guid = guid;
}
public Images getImages(){
return this.images;
}
public void setImages(Images images){
this.images = images;
}
public boolean getIs_locked(){
return this.is_locked;
}
public void setIs_locked(boolean is_locked){
this.is_locked = is_locked;
}
public boolean getIs_mobile(){
return this.is_mobile;
}
public void setIs_mobile(boolean is_mobile){
this.is_mobile = is_mobile;
}
public boolean getIs_parental_locked(){
return this.is_parental_locked;
}
public void setIs_parental_locked(boolean is_parental_locked){
this.is_parental_locked = is_parental_locked;
}
public String getKind(){
return this.kind;
}
public void setKind(String kind){
this.kind = kind;
}
public String getMobile_networks(){
return this.mobile_networks;
}
public void setMobile_networks(String mobile_networks){
this.mobile_networks = mobile_networks;
}
public String getMost_recent_full_episode_added_date(){
return this.most_recent_full_episode_added_date;
}
public void setMost_recent_full_episode_added_date(String most_recent_full_episode_added_date){
this.most_recent_full_episode_added_date = most_recent_full_episode_added_date;
}
public String getName(){
return this.name;
}
public void setName(String name){
this.name = name;
}
public List getNetworks(){
return this.networks;
}
public void setNetworks(List networks){
this.networks = networks;
}
public String getPlatforms(){
return this.platforms;
}
public void setPlatforms(String platforms){
this.platforms = platforms;
}
public List getRatings(){
return this.ratings;
}
public void setRatings(List ratings){
this.ratings = ratings;
}
public String getRelease_date(){
return this.release_date;
}
public void setRelease_date(String release_date){
this.release_date = release_date;
}
public List getSeason_filters(){
return this.season_filters;
}
public void setSeason_filters(List season_filters){
this.season_filters = season_filters;
}
public String getSlug(){
return this.slug;
}
public void setSlug(String slug){
this.slug = slug;
}
public String getTms_id(){
return this.tms_id;
}
public void setTms_id(String tms_id){
this.tms_id = tms_id;
}
}
这里是主要功能:
public class Hilda {
public static boolean b ;
public static WebDriver driver;
public static int countingCrows(WebDriver driver) throws InterruptedException{
int i,j=0,k=0;
for(i=1; i<=2; i++){
for(j=1; j<=6; j++){
if(!(i==1&&j==6)){
b = driver.findElement(By.xpath("//div[2]/div[5]/div[3]/div/div/div/div[1]/div/div[2]/div[2]/div/div["+i+"]/ul/li["+j+"]/div/a/img")).isEnabled();
k++;
//System.out.println("k inner loop:"+k);
}
if(i==1&&j==5){
Thread.sleep(5000);
try{
boolean c = driver.findElement(By.xpath("//div[2]/div[5]/div[3]/div/div/div/div[1]/div/div[2]/div[2]/div/div[1]/ul/li[6]/div/a/img")).isEnabled();
if(c){
k++;
//System.err.println("k inside j==5 for sixsth element:"+k);
}
}catch (Exception e) {
System.err.println("sixsth elemnet not found in first row");
}
}
}
if(i==1&&j==5){
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@class='carousel-control left']")).click();
}
}
System.out.println("total no :"+k);
return k;
}
public static String[] unchained(WebDriver driver) throws InterruptedException{
Thread.sleep(5000);
int j = countingCrows(driver);
int i,k=0;
String[] singleText1 = new String[11];
if(j==11){
for(i=1; i<=2; i++){
for(j=1; j<=6; j++){
if(!(i==1&&j==6)){
singleText1[k] = driver.findElement(By.xpath("//div[2]/div[5]/div[3]/div/div/div/div[1]/div/div[2]/div[2]/div/div["+i+"]/ul/li["+j+"]/div/a/img")).getAttribute("id");
//boolean b = driver.findElement(By.xpath("//div[2]/div[5]/div[3]/div/div/div/div[1]/div/div[2]/div[2]/div/div["+i+"]/ul/li["+j+"]/div/a/img")).isEnabled();
//System.out.print(j-1+"-"+singleText1[k]); System.out.println("-"+b);
k++;
}else {
System.err.println("element div[1] div[6] is not present");
}
}
if(j==5){
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@class='carousel-control left']")).click();
}
}
}
return singleText1;
}
public static void main(String[] args) throws InterruptedException, JsonParseException, JsonMappingException, IOException {
WebDriver driver = new SafariDriver();
driver.get("http://www.dishanywhere.com");
Thread.sleep(5000);
String [] cottonSack =unchained(driver);
System.out.println("*******************************************************");
int j = countingCrows(driver);
/*for(int i= 0;i<=j-1;i++){
System.out.println(cottonSack[i]);
}*/
BossMan calvin = new BossMan();
String[] dogs = calvin.candie();
for(int k=0;k<cottonSack.length;k++){
boolean c = dogs[k].equalsIgnoreCase(cottonSack[k]);
if(c){
System.out.println("Comparing json data- " +dogs[k]+" with webpage data- "+cottonSack[k]+" and Result is- "+c);
}else {
System.out.println("Comparing json data- " +dogs[k]+" with webpage data- "+cottonSack[k]+" Result- "+c);
}
}
}
}
最佳答案
错误是:
Can not deserialize instance of java.lang.String out of START_ARRAY token at [Source: line: 1, column: 1095] (through reference chain: JsonGen["platforms"])
在 JSON 中,platforms
如下所示:
"platforms": [
{
"platform": "iphone"
},
{
"platform": "ipad"
},
{
"platform": "android_phone"
},
{
"platform": "android_tablet"
}
]
所以试着把你的 pojo 改成这样:
private List platforms;
public List getPlatforms(){
return this.platforms;
}
public void setPlatforms(List platforms){
this.platforms = platforms;
}
编辑:您也需要更改 mobile_networks
。看起来像这样:
private List mobile_networks;
public List getMobile_networks() {
return mobile_networks;
}
public void setMobile_networks(List mobile_networks) {
this.mobile_networks = mobile_networks;
}
关于java - 无法从 START_ARRAY token 中反序列化 java.lang.String 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27911591/
我需要像这样反序列化 Json: { "arrayObj1":[ { "type":"t1", "value":[
我正在编写一个使用 robospice、retrofit 和 Jackson 2.4.X 的 Android 应用程序, 这是我试图反序列化从休息服务返回的 json。返回的“data”数组中的元素是
我在从我们从 EXTJS 存储发送的 JSON 文件中反序列化多个任务(数据)时遇到问题。在更新单个任务时它的工作正常。但是当我们更新多个任务时,它会显示 org.codehaus.jackson.m
我有两个对象,一个是 Dashboard,第二个是 Room 我有一个 json,看起来像这样 { "hotel_id":"1", "hotel_room":"200", "hotel_prope
我在尝试解析之前使用 Jackson 生成的一些 JSON 时收到此错误。我像这样生成 JSON String ret = ""; ret = mapper.writeValueAsString(me
我需要向网络服务发送一个发布请求,但它返回以下异常 java.io.IOException: Server returned HTTP response code: 500 for URL doma
谁能说我哪里做错了。我有这样的 json [{"name":"foo","slug":"foo2","locales":["foo3"],"hostname":"foo4","region_tag":
我是 Spring Boot 和 API 的新手,我正在开发一个项目,尽管我的 Spring Boot 应用程序与 MySQL 数据库连接,但我需要从公共(public) API 获取数据并将其存储到
我正在尝试使用 jackson api 解析 json,并包含以下详细信息。但我收到错误。请查找以下代码和堆栈跟踪详细信息。 JSON [{"id":1001,"cyPerReffe":1200,"d
我正在尝试将我的 json 请求解析为我的模型。我不知道,这段代码有什么问题。 json 的语法看起来是正确的,Java 模型上的注释也是如此。我不知道为什么我会收到如下错误: Caused by:
我有一个 SpringBoot 应用程序。使用此配置文件: @Configuration public class ApplicationConfig { @Bean public R
我有一个带有restTemplate调用的方法,如下所示: restTemplate.getForObject(apiUrl ,Someclass.class); Someclass.class: @
我正在尝试通过 jQuery AJAX 将对象数组发送到 Spring Controller 。这是 JavaScript 代码: var data = new Array(); $.
我在这个问题上遇到了同样的问题,很高兴看到这个问题已经有了解决方案。但我无法在我的代码中实现它。 ( Cannot deserialize instance of object out of STAR
我正在尝试为我的索引更新文档,并在通过 Postman 更新 API 脚本时收到以下错误 { "error": { "root_cause": [ {
直接开始... 我有一个返回字符串的方法(请参阅下面的示例字符串) - 本质上,我向 URL 发出 HTTP GET 请求,响应是下面的字符串... { "total": 30, "rows"
我有一个像这样的json: { "games": [ { "id": "mhhlhlmlezgwniokgawxloi7mi", "from": "42
我知道 stackoverflow 上有一些关于这个问题的问题。但我花了几个小时试图解决这个错误,但没有成功。 我使用 mysql 数据库来存储值。 我不断收到来自com.example.spring
JSON 片段如下: "text": {"paragraph": [ "For use in manufacturing only.",
我必须从 servlet 中收到的 JSON 字符串创建 Java 对象下面是 JSON [{"name":"name","value":"Shital"},{"name":"email","valu
我是一名优秀的程序员,十分优秀!