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)
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);
}
}
}
}
错误是:
无法反序列化[源:行:1,列:1095]处的START_ARRAY标记外的java.lang.String实例(通过引用链:jsongen[“Platforms”])
在JSON中,platforms
如下所示:
"platforms": [
{
"platform": "iphone"
},
{
"platform": "ipad"
},
{
"platform": "android_phone"
},
{
"platform": "android_tablet"
}
]
private List platforms;
public List getPlatforms(){
return this.platforms;
}
public void setPlatforms(List platforms){
this.platforms = platforms;
}
private List mobile_networks;
public List getMobile_networks() {
return mobile_networks;
}
public void setMobile_networks(List mobile_networks) {
this.mobile_networks = mobile_networks;
}
我需要向网络服务发送帖子请求,但它在异常后返回。 实际服务器响应如下: 我根据以下内容发送请求 我的代码
例外情况: 套接字处理程序 我相信当JSON被解析为WorkstationRequest对象时会出现异常,原因是下面的项。这是套接字处理程序: 我不知道如何开始调试它。堆栈跟踪从未触及我的应用程序。我正在使用部署我的.jar,并使用执行它
我尝试使用jacksonapi解析json,并提供以下详细信息。但我错了。请查找以下代码和堆栈跟踪的详细信息。 JSON 控制器类 下面这个类是我的bean类。PublisheData.java 发布数据列表.java 我收到以下错误。
我编写了一个微服务来对API进行HTTP调用。代码如下所示。 当我使用构建它时,它运行得非常完美。然而,当我将其作为SpringBoot应用程序运行时,我会得到以下错误:
我尝试声明为String或List,但没有成功。知道吗? }