{
query: "rann of kutch",
response: {
image: [
"http://www.ouralaskancruise.com/wp-content/uploads/2010/05/Princess_Denali_Express_Rail.jpg"
],
source: "chatbot",
text: "Very interesting.",
time: 5572
},
uid: "11222"
}
String responseJson = null;
try {
responseJson = Utils.executeHttpGet(url);
} catch (Exception e) {
if (e != null) {
error = e.getMessage();
e.printStackTrace();
}
}
public class ResponseDetails {
public String query;
public String uid;
public Response response;
}
public class Response {
public Image image;
public String source;
public String text;
public long time;
}
public class Image {
public ArrayList<String> urls;
//public String url;
}
11-07 18:48:34.321: W/System.err(15921): com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of com.Travel.TravelChat.DataClasses.Image out of START_ARRAY token
11-07 18:48:34.321: W/System.err(15921): at [Source: java.io.StringReader@417fbc70; line: 4, column: 5] (through reference chain: com.Travel.TravelChat.DataClasses.ResponseDetails["response"]->com.Travel.TravelChat.DataClasses.Response["image"])
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:575)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.DeserializationContext.mappingException(DeserializationContext.java:569)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializerBase.deserializeFromArray(BeanDeserializerBase.java:1121)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializer._deserializeOther(BeanDeserializer.java:148)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:123)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:107)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.SettableBeanProperty.deserialize(SettableBeanProperty.java:464)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.impl.FieldProperty.deserializeAndSet(FieldProperty.java:107)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserializeFromObject(BeanDeserializer.java:295)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.deser.BeanDeserializer.deserialize(BeanDeserializer.java:121)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2888)
11-07 18:48:34.341: W/System.err(15921): at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:2034)
11-07 18:48:34.341: W/System.err(15921): at com.Travel.TravelChat.Helpers.Utils.readResponseDetailsJson(Utils.java:97)
11-07 18:48:34.341: W/System.err(15921): at com.Travel.TravelChat.Helpers.GetResponseTask.doInBackground(GetResponseTask.java:46)
11-07 18:48:34.341: W/System.err(15921): at com.Travel.TravelChat.Helpers.GetResponseTask.doInBackground(GetResponseTask.java:1)
11-07 18:48:34.341: W/System.err(15921): at android.os.AsyncTask$2.call(AsyncTask.java:264)
11-07 18:48:34.341: W/System.err(15921): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
11-07 18:48:34.341: W/System.err(15921): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
11-07 18:48:34.341: W/System.err(15921): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
11-07 18:48:34.341: W/System.err(15921): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
11-07 18:48:34.341: W/System.err(15921): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
11-07 18:48:34.341: W/System.err(15921): at java.lang.Thread.run(Thread.java:856)
11-07 18:48:34.341: W/dalvikvm(15921): threadid=11: thread exiting with uncaught exception (group=0x40c18a68)
11-07 18:48:34.351: E/AndroidRuntime(15921): FATAL EXCEPTION: AsyncTask #1
请帮忙。
谢了!
如果您希望保持对象模型,您的json应该如下所示:
{
query: "rann of kutch",
response: {
image : {
urls: ["http://www.ouralaskancruise.com/wp-content/uploads/2010/05/Princess_Denali_Express_Rail.jpg"]
},
source: "chatbot",
text: "Very interesting.",
time: 5572
},
uid: "11222"
}
编辑
正如@Chaosit所说的那样,JSON是不可更改的,将bean定义更改为
public class Response
{
public List<String> image;
public String source;
public String text;
public long time;
}
下面提到的是JSON字符串ResultString: 我想将相同的内容转换为A类的对象: B类代码为: 但是获取异常: JSONMappingException:无法从START_ARRAY标记反序列化java.util.LinkedHashMap实例
给定以下JSON文件: 我试图使用Jackson对象映射器访问JSON文件中的值。具体如下:
但是我得到了这个错误: “无法读取文档:无法反序列化com.advice.domain.family.income实例,从[source:java.io.pushbackInputStream@3d3298f9;行:1,列:2]处的START_ARRAY令牌中取出(通过引用链:java.util.ArrayList[0]);嵌套异常是com.fasterxml.jackson.databind.j
我在下面有这个查询,它返回对象“消耗”列表。我在JSON反序列化期间收到错误,请参阅下面的第二种方法。 这是例外 请问,有什么帮助吗?
我有一个高度嵌套的api响应: 我试图通过使用许多包装来解析它。因为当我想获得带令牌的字段'value'时,它只从一个dataRequest dto返回'null'。 元素DTO: 属性DTO: 然后我试着用不是最好的方式解析这棵树,但是我无法理解如何更容易地解析它?并获取上面的异常: 试图通过将JsonIgnoreProperties更改为 在valuesDto中,但最终具有相同的异常